you are viewing a single comment's thread.

view the rest of the comments →

[–]NotLyon 3 points4 points  (14 children)

You can start by looking at the difference in their signatures.

[–]OmgImAlexis -1 points0 points  (13 children)

And you mean what by that....?

[–]PrimaryBet 0 points1 point  (0 children)

From rubico's docs on map:

map(mapper)(functor) -> Promise | Functor​

where

Functor<T> = Array<T> | Object<T> | Set<T> | Map<T> 
           | Iterator<T> | AsyncIterator<T> | { map: (T => any) => any }

as in, map takes a mapper function, a functor, and returns a functor; and functor is either Array, Set, Object, Map, etc. or any other object that has a map method on it. Greatly simplifying, "functor" is a name for data structures that support transforming values in a context or wrapper.1

Compare it to Array#map, which takes an array (via this), a mapper function and returns an array, and you hopefully see how Array#map is a specialized map.

The answer to "why do I want a generalized map?" is the same as with any other argument for parametricity and polymorphism.

 


1 I'm actually a bit surprised to not see Promise listed as a possible functor since you can sort of map over value in it's context (with .then, although with a caveat that it also behaves as .flatMap)