Profunctor

@implicitNotFound("Could not find an instance of Profunctor for ${F}") @typeclass trait Profunctor[F[_, _]] extends Serializable

A Profunctor is a Contravariant functor on its first type parameter and a Functor on its second type parameter.

A Profunctor is a Contravariant functor on its first type parameter and a Functor on its second type parameter.

Must obey the laws defined in cats.laws.ProfunctorLaws.

Companion
object
trait Serializable
class Object
trait Matchable
class Any
trait Strong[F]
trait Arrow[F]
trait ArrowChoice[F]

Value members

Abstract methods

def dimap[A, B, C, D](fab: F[A, B])(f: C => A)(g: B => D): F[C, D]

Contramap on the first type parameter and map on the second type parameter

Contramap on the first type parameter and map on the second type parameter

Example:

scala> import cats.implicits._
scala> import cats.arrow.Profunctor
scala> val fab: Double => Double = x => x + 0.3
scala> val f: Int => Double = x => x.toDouble / 2
scala> val g: Double => Double = x => x * 3
scala> val h = Profunctor[Function1].dimap(fab)(f)(g)
scala> h(3)
res0: Double = 5.4

Concrete methods

def leftNarrow[A, B, AA <: A](fab: F[A, B]): F[AA, B]

Narrows A into a subtype AA. Example:

Narrows A into a subtype AA. Example:

scala> import cats.syntax.profunctor._
scala> import cats.instances.function._
scala>
scala> sealed trait Foo
scala> case object Bar extends Foo
scala> val x1: Foo => Int = _ => 1
scala> val x2: Bar.type => Int = x1.leftNarrow
def lmap[A, B, C](fab: F[A, B])(f: C => A): F[C, B]

contramap on the first type parameter

contramap on the first type parameter

def rightWiden[A, B, BB >: B](fab: F[A, B]): F[A, BB]

Widens B into a supertype BB. Example:

Widens B into a supertype BB. Example:

scala> import cats.syntax.profunctor._
scala> import cats.instances.function._
scala>
scala> sealed trait Foo
scala> case object Bar extends Foo
scala> val x1: Int => Bar.type = _ => Bar
scala> val x2: Int => Foo = x1.rightWiden
def rmap[A, B, C](fab: F[A, B])(f: B => C): F[A, C]

map on the second type parameter

map on the second type parameter