As for:
Enum
does not (contrary to what intuition might suggest) implement the Functor (fun_land
source code) pattern. Thus Enum.map
is not a 'true map` because indeed it (and all functions that are based on it) always returns a list rather than ‘a container with transformed contents but with the same containing structure’.
Instead of on map
, Enum
is built on the concept of reduce
Reducable(fun_land
source code) or, in Haskell parlance, Foldable is a an interface that is implementable for a larger group of datatypes than Mappable, because things like sets and numerical ranges can be reduced but not mapped (since then it would be possible to end up with two values with the same value, which goes against the invariant of a set).
So why do you care about Functor-style ‘true’ map
? Because Enum.map
and similar functions throw away the structure of the container. If you have a (rose) tree, good luck on iterating it using Enum.map
and in the end attempting to regain the same tree structure as before.
I have the feeling (please correct me if I’m wrong, @josevalim) that the current approach of Enum.map
being built on top of reduce
was to be able to use iteration functions with these other data types, and that this choice might’ve been influenced by Ruby, which takes the same approach.