Hacker News new | ask | show | jobs
by kovrik 2622 days ago
In the 'Glimpse of Muon' example, how does the Map::getOrDefault() function work? Shouldn't it accept 2 args: a key and a default value (if the value associated with the given key is not found)?
2 comments

Sibling comment (granzymes) is correct, also see implementation here: https://github.com/nickmqb/muon/blob/d557c18d2dcd3fc15a7a7a6...

In Muon, you can always add more functions to an existing namespace, so if you wanted to have a function with that behavior you could add it.

If the key isn't present in a Map<K, V> it returns the default_value of the type V (which is 0 for integers).