Differences
This shows you the differences between two versions of the page.
fp:lecture09 [2022/05/03 12:39] pdmatei created |
fp:lecture09 [2022/05/06 10:47] (current) pdmatei |
||
---|---|---|---|
Line 86: | Line 86: | ||
val g2 = gradebook.withDefaultValue(0) // a new gradebook that returns 0 for non-existent keys | val g2 = gradebook.withDefaultValue(0) // a new gradebook that returns 0 for non-existent keys | ||
// THIS MAKES GRADEBOOK A TOTAL FUNCTION | // THIS MAKES GRADEBOOK A TOTAL FUNCTION | ||
+ | |||
+ | g2 + ("Matei" -> 0) // updates the current map with a new key/value entry. If the key exists, it will be updated. The function returns a new map | ||
+ | |||
+ | g2 ++ Map("A" -> 0, "B" -> 1) // merges two maps | ||
g2("Matei") | g2("Matei") |