3 ms·
Comparing with immutablejs, there are 4 broad categories that match: lists, dicts, sets, and iterators. Tuple slicing and concatenation gives you the "immutabl
by xapata 9y ago
Comparing with immutablejs, there are 4 broad categories that match: lists, dicts, sets, and iterators.
Tuple slicing and concatenation gives you the "immutable" behavior for ordered data. For sets and dicts, one could create a subclass that override add/insert/set methods to return a modified copy. Iterators already have excellent support.
I'm not an immutablejs user, but my first skim of the docs doesn't make it clear what's missing from Python. If the immutable subclasses would be valuable, I'll gladly make a module for it. There's already frozenset. A frozendict didn't seem as useful (according to core devs).
- xapata 9y agoPlus, I forgot that sets have nice operators for union, intersection, etc. So you don't need to override anything there.