Module: functor

Methods

(static) fmap(f, a) → {Object}

Map a function over a functor, a data type that specifies how functions may be mapped over it.
Haskell> fmap :: (a -> b) -> f a -> f b

Parameters:
Name Type Description
f function

The function to map

a Object

The functor to map over

Source:
Returns:

A new functor of the same type, the result of the mapping

Type
Object
Example
const lst = list(1,2,3);  // => [1:2:3:[]]
fmap(id, lst);            // => [1:2:3:[]]
const f = x => x * 11;
const g = x => x * 100;
$(fmap(f))(fmap(g))(lst); // => [1100:2200:3300:[]]
fmap($(f)(g))(lst);       // => [1100:2200:3300:[]]

(static) fmapReplaceBy(a, b) → {Object}

Replace all locations in a functor with the same value.
Haskell> (<$) :: a -> f b -> f a

Parameters:
Name Type Description
a *

The value to inject into the functor

b Object

The functor to map over

Source:
Returns:

A new functor of the same type, with the values of the original replaced by the new value

Type
Object
Example
const lst = list(1,2,3); // => [1:2:3:[]]
fmapReplaceBy(5, lst);   // => [5:5:5:[]]

(static) Functor() → {boolean}

A Functor is a type that can be mapped over. This includes lists and other collections, but functions themselves as well as other sorts of values could conceivably be mapped over, so no one metaphor covers all possible cases.

Parameters:
Type Description
*

Any object

Source:
Returns:

true if an object is an instance of Functor and false otherwise

Type
boolean