Closed Heermod closed 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!
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?