Tip to tail Kleisli arrow composition.
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)
Composes run with a function B => F[C]
not lifted into Kleisli.
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)
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)
Modify the context F
using transformation f
.
Discard computed B and yield the input value.
Yield computed B combined with input value.
Represents a function
A => F[B]
.