Contravariant

zio.prelude.Contravariant
See theContravariant companion object

Contravariant[F] provides implicit evidence that F[-_] is a contravariant endofunctor in the category of Scala objects.

Contravariant instances of type F[A] "consume" values of type A in some sense. For example, Equal[A] takes two values of type A as input and returns a Boolean indicating whether they are equal. Similarly, a Ord[A] takes two values of type A as input and returns an Ordering with the result of comparing them and Hash takes an A value and returns an Int.

Common examples of contravariant instances in ZIO include effects with regard to their environment types, sinks with regard to their input type, and polymorphic queues and references regarding their input types.

Contravariant instances support a contramap operation, which allows transforming the input type given a function from the new input type to the old input type. For example, if we have an Ord[Int] that allows us to compare two integers and we have a function String => Int that returns the length of a string, then we can construct an Ord[String] that compares strings by computing their lengths with the provided function and comparing those.

Attributes

Companion
object
Graph
Supertypes
trait Invariant[F]
class Object
trait Matchable
class Any
Known subtypes
Self type

Members list

Value members

Abstract methods

def contramap[A, B](f: B => A): (F[A]) => F[B]

Lift a function from B to A to a function from F[A] to F[B].

Lift a function from B to A to a function from F[A] to F[B].

Attributes

Concrete methods

final def compose[G[_]](implicit g: Contravariant[G]): Covariant[{ type lambda = [A] =>> F[G[A]]; }#<none>]

Compose two contravariant functors.

Compose two contravariant functors.

Attributes

final def compose[G[_]](implicit g: Covariant[G]): Contravariant[{ type lambda = [A] =>> F[G[A]]; }#<none>]

Compose contravariant and covariant functors.

Compose contravariant and covariant functors.

Attributes

final def contramapSubset[A, B : AnyType](f: B => A): (F[A]) => F[B]
final def invmap[A, B](f: Equivalence[A, B]): Equivalence[F[A], F[B]]

Inherited methods

final def compose[G[_]](implicit g: Invariant[G]): Invariant[{ type lambda = [A] =>> F[G[A]]; }#<none>]

Compose two invariant functors.

Compose two invariant functors.

Attributes

Inherited from:
Invariant
def compositionLaw[A, B, C](fa: F[A], f: Equivalence[A, B], g: Equivalence[B, C])(implicit equal: Equal[F[C]]): Boolean

Attributes

Inherited from:
Invariant
def identityLaw1[A](fa: F[A])(implicit equal: Equal[F[A]]): Boolean

Attributes

Inherited from:
Invariant