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
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
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
Represents a function
F[A] => B
.