Creates a FunctionK
that transforms a Kleisli[F, A, B]
into an F[B]
by applying the value of type a:A
.
Creates a FunctionK
that transforms a Kleisli[F, A, B]
into an F[B]
by applying the value of type a:A
.
scala> import cats.{~>}, cats.data.{Kleisli, EitherT} scala> def f(i: Int): Option[Either[Char, Char]] = if (i > 0) Some(Right('n')) else if (i < 0) Some(Left('z')) else None scala> type KOI[A] = Kleisli[Option, Int, A] scala> val b: KOI[Either[Char, Char]] = Kleisli[Option, Int, Either[Char, Char]](f _) scala> val nt: Kleisli[Option, Int, ?] ~> Option = Kleisli.applyK[Option, Int](1) scala> nt(b) res0: Option[Either[Char, Char]] = Some(Right(n)) scala> type EKOIC[A] = EitherT[KOI, Char, A] scala> val c: EKOIC[Char] = EitherT[KOI, Char, Char](b) scala> c.mapK(nt).value res1: Option[Either[Char, Char]] = Some(Right(n)) scala> val ntz = Kleisli.applyK[Option, Int](0) scala> c.mapK(ntz).value res2: Option[Either[Char, Char]] = None
Creates a Kleisli arrow which can lift an A
into applicative context F
.
Creates a Kleisli arrow which can lift an A
into applicative context F
.
This is distinct from pure in that the input is what is lifted (and not ignored).
scala> Kleisli.ask[Option, Int].run(1) res0: Option[Int]: Some(1)
Witness for: Kleisli[M, E, A] <-> (E, R) => A if M is Representable
Witness for: Kleisli[M, E, A] <-> (E, R) => A if M is Representable
Creates a Kleisli that ignores its input A
and returns the given F[B]
.
Creates a Kleisli that ignores its input A
and returns the given F[B]
.
scala> import cats.data.Kleisli, cats.implicits._ scala> val takeHead = Kleisli((_:List[Int]).headOption) scala> val makeList = Kleisli.liftF[Option, Unit, List[Int]](Some(List(1,2,3))) scala> (makeList andThen takeHead).run(()) res0: Option[Int] = Some(1)
Lifts a natural transformation of effects within a Kleisli to a transformation of Kleislis.
Lifts a natural transformation of effects within a Kleisli to a transformation of Kleislis.
Equivalent to running mapK(f) on a Kleisli.
scala> import cats._, data._ scala> val f: (List ~> Option) = λ[List ~> Option](_.headOption) scala> val k: Kleisli[List, String, Char] = Kleisli(_.toList) scala> k.run("foo") res0: List[Char] = List(f, o, o) scala> val k2: Kleisli[Option, String, Char] = Kleisli.liftFunctionK(f)(k) scala> k2.run("foo") res1: Option[Char] = Some(f)
Same as liftF, but expressed as a FunctionK for use with mapK
Same as liftF, but expressed as a FunctionK for use with mapK
scala> import cats._, data._, implicits._ scala> val a: OptionT[Eval, Int] = 1.pure[OptionT[Eval, ?]] scala> val b: OptionT[Kleisli[Eval, String, ?], Int] = a.mapK(Kleisli.liftK) scala> b.value.run("").value res0: Option[Int] = Some(1)
Modifies the input environment with f
, without changing the input type of the Kleisli.
Modifies the input environment with f
, without changing the input type of the Kleisli.
scala> import cats.data.Kleisli scala> val takeHead = Kleisli[Option, List[Int], Int](_.headOption) scala> Kleisli.local[Option, Int, List[Int]](1 :: _)(takeHead).run(List(2,3)) res0: Option[Int] = Some(1)
Creates a Kleisli arrow ignoring its input and lifting the given B
into applicative context F
.
Creates a Kleisli arrow ignoring its input and lifting the given B
into applicative context F
.
scala> import cats.data.Kleisli, cats.implicits._ scala> val pureOpt = Kleisli.pure[Option, Unit, String]("beam me up!") scala> pureOpt.run(()) res0: Option[String] = Some(beam me up!)
(Since version 1.0.0-RC2) Use liftF instead