2 ms·
Is it critical in some way that's absent from all the other langugaes that have a map()? There are standard, composable, explicit patterns in Python, Clojure, a
by fulafel 5y ago
Is it critical in some way that's absent from all the other langugaes that have a map()? There are standard, composable, explicit patterns in Python, Clojure, and I presume other map()-equipped anguages to get you the indices along with the items. (enumerate in Python and map-indexed in Clojure)
The error I was talking about was the argument count mismatch erorr, that would have taught you on all the other times you used map() without knowing about the extra index argument.
- dragonwriter 5y ago> Is it critical in some way that’s absent from all the other langugaes that have a map()? Yes, but only because of other non-ergonomic design decisions of the API its part of (particuarly, that it is an eager API attached to the Array class returning Arrays; if it were a lazy API of generalized iterable protocol that returned and could be used on generators, then you could just also have an “enumerate” and “with_collection” companion methods, but as it is, even if you made standalone functions for those purposes, for the output to be used with .map() you need them to return Arrays, which means you are accumulating bulky intermediate results.)
- fulafel 5y agoYes, eagerness would use additional space in the case of a Python enumerate() style solution. This would be acceptable in my view and aligned with the general JS design. But an alternative is the map-indexed style solution (aka the current Array.map with a different name).