Cokleisli

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

Represents a function F[A] => B.

Represents a function F[A] => B.

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

Value members

Concrete methods

def andThen[C](c: Cokleisli[F, B, C])(F: CoflatMap[F]): Cokleisli[F, A, C]
def compose[C](c: Cokleisli[F, C, A])(F: CoflatMap[F]): Cokleisli[F, C, B]
def contramapValue[C](f: F[C] => F[A]): Cokleisli[F, C, B]

Example:

Example:

scala> import cats._, data._
scala> val sum = Cokleisli((xs: NonEmptyList[Int]) => xs.reduceLeft(_ + _))

scala> sum.contramapValue((xs: NonEmptyList[String]) => xs.map(_.toInt)).run(NonEmptyList.of("1","2","3"))
res4: Int = 6
def dimap[C, D](f: C => A)(g: B => D)(F: Functor[F]): Cokleisli[F, C, D]

Example:

Example:

scala> import cats._, data._
scala> val f = Cokleisli((xs: NonEmptyList[Int]) => xs.reverse.head)
scala> def before(x: Double) = x.toInt
scala> def after(x: Int) = x.toString
scala> f.dimap(before)(after).run(NonEmptyList.of(1.0,2.0))
res0: String = 2
def first[C](F: Comonad[F]): Cokleisli[F, (A, C), (B, C)]
def flatMap[C](f: B => Cokleisli[F, A, C]): Cokleisli[F, A, C]
def lmap[C](f: C => A)(F: Functor[F]): Cokleisli[F, C, B]

Example:

Example:

scala> import cats._, data._, implicits._
scala> val f = Cokleisli((xs: NonEmptyList[Int]) => xs.reverse.head)
scala> def before(x: Double) = x.toInt
scala> def after(x: Int) = x.toString
scala> f.lmap(before).rmap(after).run(NonEmptyList.of(1.0,2.0))
res0: String = 2
def map[C](f: B => C): Cokleisli[F, A, C]
def second[C](F: Comonad[F]): Cokleisli[F, (C, A), (C, B)]

Inherited methods

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