Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Comment

HashTable is a trait without a factory method and thus cannot be instantiated. HashMap and HashSet are subclasses that you should use.

https://stackoverflow.com/questions/3648870/scala-using-hashmap-with-a-default-value

m = Map(x -> 24, y -> 25)
Map(x -> 24, y -> 25)
24
x: 24
y: 25
x: 24
y: 25
true
false
true
class scala.collection.immutable.HashMap$HashTrieMap

toMap

Map(Ben -> 1, Lisa -> 2)
Map(Ben -> 1, Lisa -> 2)

Seq of Tuple to Map

Loading...

Notice that if a key appears more than once, the last occurrence is used.

Loading...

You can manually define the behavior of aggregation of course. For example, the code below sum values belong to the same key.

Loading...

Count Frequencies of Values

Loading...

Iterate a Map

Loading...
select * from table where id in (${x}, ${y})
select * from table where id in (24, 25)

Join Lists

[[(Ben,1000.0), (Tiger,2000.0)]]
join: (c1: List[(String, Double)], c2: List[(String, Double)])List[(Double, Double)]
[[(1.0,1000.0)]]