M
- Type M<?> of a monadic instance, which is covered by this MonadT
- component type of this monadpublic interface Monad<M extends Kind1<M,?>,T> extends Functor<T>
A Monad
is a Functor
with a flatMap
method that satisfies the Monad laws, also known
as the three control laws:
Let
A
, B
, C
be typesunit: A -> Monad<A>
a constructorf: A -> Monad<B>
, g: B -> Monad<C>
functionsa
be an object of type A
m
be an object of type Monad<A>
Monad
interface should obey the three control laws:
unit(a).flatMap(f) ≡ f a
m.flatMap(unit) ≡ m
m.flatMap(f).flatMap(g) ≡ m.flatMap(x -> f.apply(x).flatMap(g))
Modifier and Type | Interface and Description |
---|---|
static interface |
Monad.Lifted1<T,R>
Represents a function
T -> R
lifted to M<T> -> M<R> . |
static interface |
Monad.Lifted2<T1,T2,R>
Represents a function
(T1, T2) -> R
lifted to (M<T1>, M<T2>) -> M<R> . |
static interface |
Monad.Lifted3<T1,T2,T3,R>
Represents a function
(T1, T2, T3) -> R
lifted to (M<T1>, M<T2>, M<T3>) -> M<R> . |
static interface |
Monad.Lifted4<T1,T2,T3,T4,R>
Represents a function
(T1, T2, T3, T4) -> R
lifted to (M<T1>, M<T2>, M<T3>, M<T4>) -> M<R> . |
static interface |
Monad.Lifted5<T1,T2,T3,T4,T5,R>
Represents a function
(T1, T2, T3, T4, T5) -> R
lifted to (M<T1>, M<T2>, M<T3>, M<T4>, M<T5>) -> M<R> . |
static interface |
Monad.Lifted6<T1,T2,T3,T4,T5,T6,R>
Represents a function
(T1, T2, T3, T4, T5, T6) -> R
lifted to (M<T1>, M<T2>, M<T3>, M<T4>, M<T5>, M<T6>) -> M<R> . |
static interface |
Monad.Lifted7<T1,T2,T3,T4,T5,T6,T7,R>
Represents a function
(T1, T2, T3, T4, T5, T6, T7) -> R
lifted to (M<T1>, M<T2>, M<T3>, M<T4>, M<T5>, M<T6>, M<T7>) -> M<R> . |
static interface |
Monad.Lifted8<T1,T2,T3,T4,T5,T6,T7,T8,R>
Represents a function
(T1, T2, T3, T4, T5, T6, T7, T8) -> R
lifted to (M<T1>, M<T2>, M<T3>, M<T4>, M<T5>, M<T6>, M<T7>, M<T8>) -> M<R> . |
Modifier and Type | Method and Description |
---|---|
<U> Monad<M,U> |
flatMap(Function<? super T,? extends Monad<M,U>> mapper)
FlatMaps this Monad to a new Monad with different component type.
|
static <T1,T2,R> Monad.Lifted2<T1,T2,R> |
lift(BiFunction<? super T1,? super T2,? extends R> f)
Lifts a
BiFunction to a higher Lifted2 function that operates on Monads. |
static <T,R> Monad.Lifted1<T,R> |
lift(Function<? super T,? extends R> f)
Lifts a
Function to a higher Lifted1 function that operates on Monads. |
static <T1,T2,T3,R> |
lift(Function3<? super T1,? super T2,? super T3,? extends R> f)
Lifts a
Function3 to a higher Lifted3 function that operates on Monads. |
static <T1,T2,T3,T4,R> |
lift(Function4<? super T1,? super T2,? super T3,? super T4,? extends R> f)
Lifts a
Function4 to a higher Lifted4 function that operates on Monads. |
static <T1,T2,T3,T4,T5,R> |
lift(Function5<? super T1,? super T2,? super T3,? super T4,? super T5,? extends R> f)
Lifts a
Function5 to a higher Lifted5 function that operates on Monads. |
static <T1,T2,T3,T4,T5,T6,R> |
lift(Function6<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? extends R> f)
Lifts a
Function6 to a higher Lifted6 function that operates on Monads. |
static <T1,T2,T3,T4,T5,T6,T7,R> |
lift(Function7<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? extends R> f)
Lifts a
Function7 to a higher Lifted7 function that operates on Monads. |
static <T1,T2,T3,T4,T5,T6,T7,T8,R> |
lift(Function8<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? super T8,? extends R> f)
Lifts a
Function8 to a higher Lifted8 function that operates on Monads. |
<U> Monad<M,U> |
map(Function<? super T,? extends U> mapper)
Applies a function
f to the components of this Functor. |
Kind1<M,T> |
narrow()
Pulls the monadic instance of type M<?> out of this Monad view.
|
static <T> Monad<List<?>,T> |
of(List<T> list) |
<U> Monad<M,U> flatMap(Function<? super T,? extends Monad<M,U>> mapper)
FlatMap is the sequence operation for functions and behaves like the imperative ;
.
If the previous results are needed, flatMap cascades:
m1().flatMap(result1 ->
m2(result1).flatMap(result2 ->
m3(result1, result2).flatMap(result3 ->
...
)
)
);
If only the last result is needed, flatMap may be used sequentially:
m1().flatMap(this::m2)
.flatMap(this::m3)
.flatMap(...);
U
- Component type of the mapped Monad
mapper
- A mapperMonad
NullPointerException
- if mapper
is null<U> Monad<M,U> map(Function<? super T,? extends U> mapper)
Functor
f
to the components of this Functor.Kind1<M,T> narrow()
static <T,R> Monad.Lifted1<T,R> lift(Function<? super T,? extends R> f)
Function
to a higher Lifted1
function that operates on Monads.T
- 1st argument type of fR
- result type of ff
- a Functionstatic <T1,T2,R> Monad.Lifted2<T1,T2,R> lift(BiFunction<? super T1,? super T2,? extends R> f)
BiFunction
to a higher Lifted2
function that operates on Monads.T1
- 1st argument type of fT2
- 2nd argument type of fR
- result type of ff
- a BiFunctionstatic <T1,T2,T3,R> Monad.Lifted3<T1,T2,T3,R> lift(Function3<? super T1,? super T2,? super T3,? extends R> f)
Function3
to a higher Lifted3
function that operates on Monads.T1
- 1st argument type of fT2
- 2nd argument type of fT3
- 3rd argument type of fR
- result type of ff
- a Function3static <T1,T2,T3,T4,R> Monad.Lifted4<T1,T2,T3,T4,R> lift(Function4<? super T1,? super T2,? super T3,? super T4,? extends R> f)
Function4
to a higher Lifted4
function that operates on Monads.T1
- 1st argument type of fT2
- 2nd argument type of fT3
- 3rd argument type of fT4
- 4th argument type of fR
- result type of ff
- a Function4static <T1,T2,T3,T4,T5,R> Monad.Lifted5<T1,T2,T3,T4,T5,R> lift(Function5<? super T1,? super T2,? super T3,? super T4,? super T5,? extends R> f)
Function5
to a higher Lifted5
function that operates on Monads.T1
- 1st argument type of fT2
- 2nd argument type of fT3
- 3rd argument type of fT4
- 4th argument type of fT5
- 5th argument type of fR
- result type of ff
- a Function5static <T1,T2,T3,T4,T5,T6,R> Monad.Lifted6<T1,T2,T3,T4,T5,T6,R> lift(Function6<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? extends R> f)
Function6
to a higher Lifted6
function that operates on Monads.T1
- 1st argument type of fT2
- 2nd argument type of fT3
- 3rd argument type of fT4
- 4th argument type of fT5
- 5th argument type of fT6
- 6th argument type of fR
- result type of ff
- a Function6static <T1,T2,T3,T4,T5,T6,T7,R> Monad.Lifted7<T1,T2,T3,T4,T5,T6,T7,R> lift(Function7<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? extends R> f)
Function7
to a higher Lifted7
function that operates on Monads.T1
- 1st argument type of fT2
- 2nd argument type of fT3
- 3rd argument type of fT4
- 4th argument type of fT5
- 5th argument type of fT6
- 6th argument type of fT7
- 7th argument type of fR
- result type of ff
- a Function7static <T1,T2,T3,T4,T5,T6,T7,T8,R> Monad.Lifted8<T1,T2,T3,T4,T5,T6,T7,T8,R> lift(Function8<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? super T8,? extends R> f)
Function8
to a higher Lifted8
function that operates on Monads.T1
- 1st argument type of fT2
- 2nd argument type of fT3
- 3rd argument type of fT4
- 4th argument type of fT5
- 5th argument type of fT6
- 6th argument type of fT7
- 7th argument type of fT8
- 8th argument type of fR
- result type of ff
- a Function8Copyright © 2016. All Rights Reserved.