7 ms·
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
by kovrik 7y 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)?
- granzymes 7y agoIf the key isn't present in a Map<K, V> it returns the default_value of the type V (which is 0 for integers).
- nickmqb 7y agoSibling comment (granzymes) is correct, also see implementation here: https://github.com/nickmqb/muon/blob/d557c18d2dcd3fc15a7a7a6ed6dbfa0fc76f400b/lib/containers.mu#L487 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.