Traversable structures support element-wise sequencing of Applicative
effects (thus also Monad
effects)
to construct new structures of the same shape as the input.
To illustrate what is meant by same shape, if the input structure is [a]
, each output structure is a list [b]
of
the same length as the input. If the input is a Tree<A>
, each output Tree<B>
has the same graph of intermediate
nodes and leaves. Similarly, if the input is a tuple (x, a)
, each output is a tuple (x, b)
, and so forth.
Every Traversable structure is both a Functor
and Foldable
.
- TraversableExtensions
- Traverse <T, F, A, B> ( this K<T, A> ta, Func<A, K<F, B>> f)
- Sequence <T, F, A> ( this K<T, K<F, A>> ta)
- TraverseM <M, T, A, B> ( this Func<A, K<M, B>> f, K<T, A> ta)
- SequenceM <T, F, A> ( this K<T, K<F, A>> ta)
- Traversable
- traverse <T, F, A, B> ( Func<A, K<F, B>> f, K<T, A> ta)
- sequence <T, F, A> ( K<T, K<F, A>> ta)
- traverseM <T, M, A, B> ( Func<A, K<M, B>> f, K<T, A> ta)
- sequenceM <T, M, A> ( K<T, K<M, A>> ta)
- Traversable <T>
class TraversableExtensions Source #
Functors representing data structures that can be transformed to structures of the same
shape by performing an Applicative
(or, therefore, Monad
) action on each element from
left to right.
A more detailed description of what same shape means, the various methods, how traversals are constructed, and example advanced use-cases can be found in the Overview section of Data.Traversable.
type | T |
method K<F, K<T, B>> Traverse <T, F, A, B> ( this K<T, A> ta, Func<A, K<F, B>> f) Source #
method K<F, K<T, A>> Sequence <T, F, A> ( this K<T, K<F, A>> ta) Source #
class Traversable Source #
method K<F, K<T, B>> traverse <T, F, A, B> ( Func<A, K<F, B>> f, K<T, A> ta) Source #
Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.
This version of traverse
works with the lifted K
types which are
sometimes difficult to work with when nested. If you need to get concrete
types out of your traversal operation then use traverse2
- it needs more
generic parameters but it retains the concrete types.
type | T | Traversable trait |
type | F | Applicative functor trait |
type | A | Bound value (input) |
type | B | Bound value (output) |
param | f | |
param | ta | Traversable structure |
returns |
method K<F, K<T, A>> sequence <T, F, A> ( K<T, K<F, A>> ta) Source #
Evaluate each action in the structure from left to right, and collect the results.
type | T | Traversable trait |
type | F | Applicative functor trait |
type | A | Bound value (input) |
param | ta | Traversable structure |
returns |
method K<M, K<T, B>> traverseM <T, M, A, B> ( Func<A, K<M, B>> f, K<T, A> ta) Source #
Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results.
type | T | Traversable trait |
type | M | Monad trait |
type | A | Bound value (input) |
type | B | Bound value (output) |
param | f | |
param | ta | Traversable structure |
returns |
method K<M, K<T, A>> sequenceM <T, M, A> ( K<T, K<M, A>> ta) Source #
Evaluate each monadic action in the structure from left to right, and collect the results.
type | T | Traversable trait |
type | M | Monad trait |
type | A | Bound value (input) |
param | ta | Traversable structure |
returns |
interface Traversable <T> Source #
Functors representing data structures that can be transformed to structures of the same
shape by performing an Applicative
(or, therefore, Monad
) action on each element from
left to right.
A more detailed description of what same shape means, the various methods, how traversals are constructed, and example advanced use-cases can be found in the Overview section of Data.Traversable.
type | T |
method K<F, K<T, B>> Traverse <F, A, B> ( Func<A, K<F, B>> f, K<T, A> ta) Source #
method K<M, K<T, B>> TraverseM <M, A, B> ( Func<A, K<M, B>> f, K<T, A> ta) Source #
method K<F, K<T, B>> TraverseDefault <F, A, B> ( Func<A, K<F, B>> f, K<T, A> ta) Source #