T
- The container type.Mu
- The witness type for this traversable.public interface Traversable<T extends K1,Mu extends Traversable _> extends Functor T
This type class may be used to e.g. produce a function ListBox<A> -> DataResult<ListBox<B>>
from a function A -> DataResult<B>
, only producing a successful result if all the original
elements were converted successfully.
Note that the implementation of Functor.map(Function, App)
inherited from Functor
can be implemented
in terms of traverse(Applicative, Function, App)
as map(f, ta) = traverse(IdF, f, ta)
. This
interface leaves that method abstract because of the differing function types in Functor.map(Function, App)
and traverse(Applicative, Function, App)
that make the default implementation outline above impossible
without an unchecked (albeit safe) cast.
Applicative
Modifier and Type | Method and Description |
---|---|
default <F extends K1,A> |
flip(Applicative F applicative,
T<F<A>> input)
Swaps the order of this container with a nested container in
input . |
<F extends K1,A,B> |
traverse(Applicative F applicative,
(A) -> F<B> function,
T<A> input)
Applies a function that produces an
Applicative effect to each value contained within
input , then builds a container with an equivalent structure containing the (unboxed) results. |
<F extends K1,A,B> F<T<B>> traverse(Applicative F applicative, (A) -> F<B> function, T<A> input)
Applicative
effect to each value contained within
input
, then builds a container with an equivalent structure containing the (unboxed) results.F
.F
- The type of the effect.A
- The input type.B
- The output type.applicative
- An instance of the Applicative
type class which defines the behavior of F
.function
- The function to apply.input
- The input container.function
to each element, if the function was
successful for every element.default <F extends K1,A> F<T<A>> flip(Applicative F applicative, T<F<A>> input)
input
.
This function is equivalent to
traverse(applicative, Function.identity(), input)
F
- The nested container type.A
- The contained type.applicative
- An instance of the Applicative
type class which defines the behavior of F
.input
- The input container.traverse(Applicative, Function, App)