Kleisli

final case class Kleisli[F[_], -A, B](run: A => F[B])

Represents a function A => F[B].

Represents a function A => F[B].

Companion
object
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any

Value members

Concrete methods

def andThen[C](f: B => F[C])(F: FlatMap[F]): Kleisli[F, A, C]

Composes run with a function B => F[C] not lifted into Kleisli.

Composes run with a function B => F[C] not lifted into Kleisli.

def andThen[C](k: Kleisli[F, B, C])(F: FlatMap[F]): Kleisli[F, A, C]

Tip to tail Kleisli arrow composition. Creates a function A => F[C] from run (A => F[B]) and the given Kleisli of B => F[C].

Tip to tail Kleisli arrow composition. Creates a function A => F[C] from run (A => F[B]) and the given Kleisli of B => F[C].

scala> import cats.data.Kleisli, cats.implicits._
scala> val takeHead = Kleisli[Option, List[Int], Int](_.headOption)
scala> val plusOne = Kleisli[Option, Int, Int](i => Some(i + 1))
scala> (takeHead andThen plusOne).run(List(1))
res0: Option[Int] = Some(2)
def ap[C, D, AA <: A](f: Kleisli[F, AA, C])(F: Apply[F], ev: As[B, C => D]): Kleisli[F, AA, D]
def apply(a: A): F[B]
def compose[Z, AA <: A](f: Z => F[AA])(F: FlatMap[F]): Kleisli[F, Z, B]
def compose[Z, AA <: A](k: Kleisli[F, Z, AA])(F: FlatMap[F]): Kleisli[F, Z, B]
def dimap[C, D](f: C => A)(g: B => D)(F: Functor[F]): Kleisli[F, C, D]

Performs local and map simultaneously.

Performs local and map simultaneously.

def first[C](F: Functor[F]): Kleisli[F, (A, C), (B, C)]
def flatMap[C, AA <: A](f: B => Kleisli[F, AA, C])(F: FlatMap[F]): Kleisli[F, AA, C]
def flatMapF[C](f: B => F[C])(F: FlatMap[F]): Kleisli[F, A, C]
def lift[G[_]](G: Applicative[G]): Kleisli[[α] =>> G[F[α]], A, B]
def local[AA](f: AA => A): Kleisli[F, AA, B]

Contramap the input using f, where f may modify the input type of the Kleisli arrow.

Contramap the input using f, where f may modify the input type of the Kleisli arrow.

scala> import cats.data.Kleisli, cats.implicits._
scala> type ParseResult[A] = Either[Throwable, A]
scala> val parseInt = Kleisli[ParseResult, String, Int](s => Either.catchNonFatal(s.toInt))
scala> parseInt.local[List[String]](_.combineAll).run(List("1", "2"))
res0: ParseResult[Int] = Right(12)
def lower(F: Applicative[F]): Kleisli[F, A, F[B]]
def map[C](f: B => C)(F: Functor[F]): Kleisli[F, A, C]

Modify the output of the Kleisli function with f.

Modify the output of the Kleisli function with f.

scala> import cats.data.Kleisli, cats.implicits._
scala> val takeHead = Kleisli[Option, List[Int], Int](_.headOption)
scala> takeHead.map(_.toDouble).run(List(1))
res0: Option[Double] = Some(1.0)
def mapF[N[_], C](f: F[B] => N[C]): Kleisli[N, A, C]
def mapK[G[_]](f: FunctionK[F, G]): Kleisli[G, A, B]

Modify the context F using transformation f.

Modify the context F using transformation f.

def second[C](F: Functor[F]): Kleisli[F, (C, A), (C, B)]
def tap[AA <: A](F: Functor[F]): Kleisli[F, AA, AA]

Discard computed B and yield the input value.

Discard computed B and yield the input value.

def tapWith[C, AA <: A](f: (AA, B) => C)(F: Functor[F]): Kleisli[F, AA, C]

Yield computed B combined with input value.

Yield computed B combined with input value.

def tapWithF[C, AA <: A](f: (AA, B) => F[C])(F: FlatMap[F]): Kleisli[F, AA, C]
def toReader: Reader[A, F[B]]
def traverse[G[_], AA <: A](f: G[AA])(F: Applicative[F], G: Traverse[G]): F[G[B]]

Inherited methods

def productElementNames: Iterator[String]
Inherited from
Product
def productIterator: Iterator[Any]
Inherited from
Product