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
,Choice2._A
,Choice2._B
,Choice3
,Choice3._A
,Choice3._B
,Choice3._C
,Choice4
,Choice4._A
,Choice4._B
,Choice4._C
,Choice4._D
,Choice5
,Choice5._A
,Choice5._B
,Choice5._C
,Choice5._D
,Choice5._E
,Choice6
,Choice6._A
,Choice6._B
,Choice6._C
,Choice6._D
,Choice6._E
,Choice6._F
,Choice7
,Choice7._A
,Choice7._B
,Choice7._C
,Choice7._D
,Choice7._E
,Choice7._F
,Choice7._G
,Choice8
,Choice8._A
,Choice8._B
,Choice8._C
,Choice8._D
,Choice8._E
,Choice8._F
,Choice8._G
,Choice8._H
,Const
,Either
,Either.Left
,Either.Right
,Identity
,LambdaIterable
,LambdaMap
,Lazy
,Lazy.Compose
,Lazy.Later
,Maybe
,Maybe.Just
,Maybe.Nothing
,RecursiveResult
,RecursiveResult.Recurse
,RecursiveResult.Terminate
,SingletonHList
,Tagged
,These
,These._A
,These._B
,These.Both
,Try
,Try.Failure
,Try.Success
,Tuple2
,Tuple3
,Tuple4
,Tuple5
,Tuple6
,Tuple7
,Tuple8
public interface Traversable<A,T extends Traversable<?,T>> extends Functor<A,T>
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 toTraversable
, 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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method 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>>
AppTravtraverse(Fn1<? super A,? extends Applicative<B,App>> fn, Fn1<? super TravB,? extends AppTrav> pure)
Applyfn
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.
-
-
-
Method Detail
-
traverse
<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)
Applyfn
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.- 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
default <B> Traversable<B,T> fmap(Fn1<? super A,? extends B> fn)
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.
-
-