Interface Traversable<A, T extends Traversable<?,T>>
- Type Parameters:
A- The type of the parameterT- The unification parameter
- All Superinterfaces:
Functor<A,T>
- All Known Implementing Classes:
Choice2, Choice3, Choice4, Choice5, Choice6, Choice7, Choice8, Const, Either, Identity, LambdaIterable, LambdaMap, Lazy, Maybe, RecursiveResult, SingletonHList, Tagged, These, Try, Tuple2, Tuple3, Tuple4, Tuple5, Tuple6, Tuple7, Tuple8
An interface for a class of data structures that can be "traversed from left to right" in a structure-preserving
way, successively applying some applicative computation to each element and collapsing the results into a single
resulting applicative.
The same rules that apply to Functor apply to Traversable, along with the following
additional 3 laws:
- naturality:
t.apply(trav.traverse(f, pure).<Object>fmap(id()).coerce()) .equals(trav.traverse(t.compose(f), pure2).<Object>fmap(id()).coerce()) - identity:
trav.traverse(Identity::new, x -> new Identity<>(x)).equals(new Identity<>(trav) - composition:
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.
-
Method Summary
Modifier and TypeMethodDescriptiondefault <B> Traversable<B, T> 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>>
AppTravtraverse(Fn1<? super A, ? extends Applicative<B, App>> fn, Fn1<? super TravB, ? extends AppTrav> pure) Applyfnto 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.
-
Method Details
-
traverse
<B, App extends Applicative<?,App>, TravB extends Traversable<B, AppTrav traverseT>, AppTrav extends Applicative<TravB, App>> (Fn1<? super A, ? extends Applicative<B, App>> fn, Fn1<? super TravB, ? extends AppTrav> pure) Applyfnto 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.- Type Parameters:
B- the resulting element typeApp- the result applicative typeTravB- this Traversable instance over BAppTrav- the full inferred resulting type from the traversal- Parameters:
fn- the function to applypure- the applicative pure function- Returns:
- the traversed Traversable, wrapped inside an applicative
-
fmap
Covariantly transmute this functor's parameter using the given mapping function. Generally this method is specialized to return an instance of the class implementing Functor.
-