Module: traversable

Methods

(static) mapM(f, m) → {Object}

Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results. This function is essentially the same as traverse but restricted to monads.
Haskell> mapM :: Monad m => (a -> m b) -> t a -> m (t b)

Parameters:
Name Type Description
f function

The function to map

m Object

The monad to traverse

Source:
Returns:

A collection of the results of the traversal

Type
Object
Example
const mb = just(1);
const lst = list(1,2,3);
const f = x => list(x + 7);
mapM(f, mb);                // => [Just [8:[]]:[]]
mapM(f, lst);               // => [[8:9:10:[]]:[[]]:[]]

(static) sequence(m) → {Object}

Evaluate each monadic action in a structure from left to right, and collect the results.
Haskell> sequence :: Monad m => t (m a) -> m (t a)

Parameters:
Name Type Description
m Object

The monadic collection of actions

Source:
Returns:

A collection of the results

Type
Object
Example
const mb = just(1);
const mmb = just(mb);
const lst = list(1,2,3);
const llst = list(lst);
sequence(mmb);           // => Just Just 1
sequence(llst);          // => [[1:[]]:[2:[]]:[3:[]]:[]]

(static) Traversable() → {boolean}

A Traversable is a functor representing data structures that can be walked over or "traversed" from left to right (useful in trees, for example). They must define a traverse method and also be instances of Functor and Foldable.

Parameters:
Type Description
*

Any object

Source:
Returns:

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

Type
boolean

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

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.
Haskell> traverse :: Applicative f => (a -> f b) -> t a -> f (t b)

Parameters:
Name Type Description
f function

The function to map

a Object

The traversable structure to traverse

Source:
Returns:

A collection of the results of the traversal

Type
Object
Example
const mb = just(1);
const tup = tuple(1,2);
const lst = list(1,2,3);
const f = x => list(x + 7);
traverse(f, mb);            // => [Just 8:[]]
traverse(f, tup);           // => [(1,9):[]]
traverse(f)(lst);           // => [[8:9:10:[]]:[]]