spebbe / dartz

Functional programming in Dart
MIT License
749 stars 60 forks source link

Empty IVector and IHashMap does not store values #84

Closed Heermod closed 2 years ago

Heermod commented 2 years ago

IHashMap<String, String> hashmap = IHashMap.empty(); hashmap.put('bar', 'foo'); print(hashmap.get('bar')); //None

IHashMap<String, String> hashmap = IHashMap.from({'bar': 'foo'}); hashmap.put('bar', 'baz'); print(hashmap.get('bar')); //Some(foo) How can I set a value?

spebbe commented 2 years ago

Hi @Heermod! All collections in dartz are immutable – that's what's so great about them! In your example above, hashmap.put returns a new instance of IHashMap, containing the new mapping while leaving hashmap unmodified. If you want mutable collections, you might be happier sticking with the built-in Dart List, Map, Set, etc.

Hope that helped!