On iteration and enumeration

Just want to make a quick remark on this:

:maps.map/2 is the Functor mapping function for maps. The reasoning is as follows: Since maps cannot contain duplicate keys, the structure would be changed if a mapping operation would also allow altering the keys. Thus, the return value of the function passed to map/2 is the value that is used for the current key at all times.


Related to this is the Extractable library I wrote a couple of months back, which allows you to enumerate collections in a one-item-per-time fashion, because that is of course one of the things that is impossible using the current Enumerable (You cannot stop in the middle using because of potential resource cleanup that has not yet happened while in :suspended-mode, as well as the rest of the collection possibly being in a non-standard format. Using :halt discards the tail of the collection however, so you cannot use that either.)

Why want one-at-a-time? Because not all operations lend themselves to the giving control to the collection paradigm.

Indeed, currently Erlang does not allow you to simply extract a single {K, V}-pair from a map (hopefully it will be added at some time in the future, there were discussions about it a while back IIRC), and therefore the map needs to be converted into a list and back again each time.


Thank you for sharing that blog post here! Very clear explanation of why Enum(erable) is the way it is today :heart_eyes:.