A
- The type of the parameterT
- The unification parameterpublic interface Traversable<A,T extends Traversable<?,T>> extends Functor<A,T>
The same rules that apply to Functor
apply to Traversable
, along with the following
additional 3 laws:
t.apply(trav.traverse(f, pure).<Object>fmap(id()).coerce())
.equals(trav.traverse(t.compose(f), pure2).<Object>fmap(id()).coerce())
trav.traverse(Identity::new, x -> new Identity<>(x)).equals(new
Identity<>(trav)
trav.traverse(f.andThen(x -> x.fmap(g)).andThen(Compose::new), x ->
new Compose<>(new Identity<>(new Identity<>(x)))).equals(new Compose<Identity, Identity,
Traversable<Object, Trav>>(trav.traverse(f, x -> new Identity<>(x)).fmap(t ->
t.traverse(g, x -> new Identity<>(x)))))
For more information, read about Traversables.
Modifier and Type | Method and Description |
---|---|
default <B> Traversable<B,T> |
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.
|
<B,App extends Applicative<?,App>,TravB extends Traversable<B,T>,AppTrav extends Applicative<TravB,App>> |
traverse(Fn1<? super A,? extends Applicative<B,App>> fn,
Fn1<? super TravB,? extends AppTrav> pure)
Apply
fn to each element of this traversable from left to right, and collapse the results into
a single resulting applicative, potentially with the assistance of the applicative's pure function. |
<B,App extends Applicative<?,App>,TravB extends Traversable<B,T>,AppTrav extends Applicative<TravB,App>> AppTrav traverse(Fn1<? super A,? extends Applicative<B,App>> fn, Fn1<? super TravB,? extends AppTrav> pure)
fn
to each element of this traversable from left to right, and collapse the results into
a single resulting applicative, potentially with the assistance of the applicative's pure function.B
- the resulting element typeApp
- the result applicative typeTravB
- this Traversable instance over BAppTrav
- the full inferred resulting type from the traversalfn
- the function to applypure
- the applicative pure functiondefault <B> Traversable<B,T> fmap(Fn1<? super A,? extends B> fn)