4 ms·
One important characteristic of the map function is that it can be used reversibly. For example, (partial map inc) is inverted by (partial map dec). If I want t
by jhuni 14y ago
One important characteristic of the map function is that it can be used reversibly. For example, (partial map inc) is inverted by (partial map dec). If I want to map over a collection by a function that takes the entire collection as an argument I'd rather use some function other then map to avoid confusion.
- justincormack 14y agoor just call a closure bound to the whole list. I think I would write the thing as a for loop though, it feels so un map like
- jhuni 14y agoAlternatively, you could partially apply the entire list to the function.
- Evbn 14y agoHmm? What is the reverse of (partial map constantFunctionReturnsZero)? A fold/reduce is just as sometimes-reversible, when paired with an appropriate unfold. (example: multiplication and factorization) I think you mean that map is self-composable, in the sense that the map function distributes over function-composition, in the same way that (in first-order functions) multiplication distributes over addition.
- jhuni 14y ago> What is the reverse of (partial map constantFunctionReturnsZero)? The function (constantly 0) is implemented as a place in order to maintain reversibility semantics: ((constantly 0) 10) ;-> (0 10) ((constantly 0) 50) ;-> (0 50) The information lost by calling the constant function is pushed to the end of the list so that it can be called reversibly. This can be applied on an entire list: (map (constantly 0) [1 2 3]) ;-> ([0 0 0] [1 2 3]) > A fold/reduce is just as sometimes-reversible The reduce function is not reversible, but the reductions function when called with a group is: (reductions + [1 2 3 4]) ;-> [1 3 6 10] The reduce value is the last element of the list so it can be retrieved by the last place: (last [1 3 6 10]) ;-> (10 [1 3 6]) > I think you mean that map is self-composable The preservation of information is more important to me then composition.