Interface Kleisli<A,B,M extends Monad<?,M>,MB extends Monad<B,M>>

Type Parameters:
A - the input argument type
M - the Monad unification parameter
MB - the output Monad type
All Superinterfaces:
Applicative<MB,Fn1<A,?>>, Cartesian<A,MB,Fn1<?,?>>, Cocartesian<A,MB,Fn1<?,?>>, Contravariant<A,Profunctor<?,MB,Fn1<?,?>>>, Fn1<A,MB>, Functor<MB,Fn1<A,?>>, Monad<MB,Fn1<A,?>>, MonadReader<A,MB,Fn1<A,?>>, MonadRec<MB,Fn1<A,?>>, MonadWriter<A,MB,Fn1<A,?>>, Profunctor<A,MB,Fn1<?,?>>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Kleisli<A,B,M extends Monad<?,M>,MB extends Monad<B,M>> extends Fn1<A,MB>
The Kleisli arrow of a Monad, manifest as simply an Fn1<A, MB>. This can be thought of as a fixed, portable Monad.flatMap(Fn1).
  • Method Details

    • andThen

      default <C, MC extends Monad<C, M>> Kleisli<A,C,M,MC> andThen(Kleisli<B,C,M,MC> after)
      Left-to-right composition of two compatible Kleisli arrows, yielding a new Kleisli arrow.
      Type Parameters:
      C - the new return parameter type
      MC - the Monad instance to return
      Parameters:
      after - the arrow to execute after this one
      Returns:
      the composition of the two arrows as a new Kleisli arrow
    • compose

      default <Z, MA extends Monad<A, M>> Kleisli<Z,B,M,MB> compose(Kleisli<Z,A,M,MA> before)
      Right-to-left composition of two compatible Kleisli arrows, yielding a new Kleisli arrow.
      Type Parameters:
      Z - the new input argument type
      MA - the Monad instance to flatMap with this arrow
      Parameters:
      before - the arrow to execute before this one
      Returns:
      the composition of the two arrows as a new Kleisli arrow
    • discardR

      default <C> Kleisli<A,B,M,MB> discardR(Applicative<C,Fn1<A,?>> appB)
      Sequence both this Applicative and appB, discarding appB's result and returning this Applicative. This is generally useful for sequentially performing side-effects.
      Specified by:
      discardR in interface Applicative<A,B>
      Specified by:
      discardR in interface Fn1<A,B>
      Specified by:
      discardR in interface Monad<A,B>
      Specified by:
      discardR in interface MonadReader<A,B,M extends Monad<?,M>>
      Specified by:
      discardR in interface MonadRec<A,B>
      Specified by:
      discardR in interface MonadWriter<A,B,M extends Monad<?,M>>
      Type Parameters:
      C - the type of appB's parameter
      Parameters:
      appB - the other Applicative
      Returns:
      this Applicative
    • contraMap

      default <Z> Kleisli<Z,B,M,MB> contraMap(Fn1<? super Z,? extends A> fn)
      Contravariantly map A <- B.
      Specified by:
      contraMap in interface Cartesian<A,B,M extends Monad<?,M>>
      Specified by:
      contraMap in interface Cocartesian<A,B,M extends Monad<?,M>>
      Specified by:
      contraMap in interface Contravariant<A,B>
      Specified by:
      contraMap in interface Fn1<A,B>
      Specified by:
      contraMap in interface Profunctor<A,B,M extends Monad<?,M>>
      Type Parameters:
      Z - the new parameter type
      Parameters:
      fn - the mapping function
      Returns:
      the mapped Contravariant functor instance
    • diMapL

      default <Z> Kleisli<Z,B,M,MB> diMapL(Fn1<? super Z,? extends A> fn)
      Contravariantly map over the argument to this function, producing a function that takes the new argument type, and produces the same result.
      Specified by:
      diMapL in interface Cartesian<A,B,M extends Monad<?,M>>
      Specified by:
      diMapL in interface Cocartesian<A,B,M extends Monad<?,M>>
      Specified by:
      diMapL in interface Fn1<A,B>
      Specified by:
      diMapL in interface Profunctor<A,B,M extends Monad<?,M>>
      Type Parameters:
      Z - the new argument type
      Parameters:
      fn - the contravariant argument mapping function
      Returns:
      an Fn1<Z, B>
    • kleisli

      static <A, B, M extends Monad<?, M>, MB extends Monad<B, M>> Kleisli<A,B,M,MB> kleisli(Fn1<? super A,? extends MB> fn)
      Adapt a compatible function into a Kleisli arrow.
      Type Parameters:
      A - the input argument type
      B - the output parameter type
      M - the Monad unification parameter
      MB - the returned Monad instance
      Parameters:
      fn - the function
      Returns:
      the function adapted as a Kleisli arrow