Trait/Object

zio.prelude

Contravariant

Related Docs: object Contravariant | package prelude

Permalink

trait Contravariant[F[-_]] extends ContravariantSubset[F, AnyType] with Invariant[F]

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.

Self Type
Contravariant[F]
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Contravariant
  2. Invariant
  3. ContravariantSubset
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def contramap[A, B](f: (B) ⇒ A): (F[A]) ⇒ F[B]

    Permalink

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

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def compose[G[+_]](implicit g: Covariant[G]): Contravariant[[-A]F[G[A]]]

    Permalink

    Compose contravariant and covariant functors.

  7. final def compose[G[-_]](implicit g: Contravariant[G]): Covariant[[+A]F[G[A]]]

    Permalink

    Compose two contravariant functors.

  8. final def compose[G[_]](implicit g: Invariant[G]): Invariant[[A]F[G[A]]]

    Permalink

    Compose two invariant functors.

    Compose two invariant functors.

    Definition Classes
    Invariant
  9. def compositionLaw[A, B, C](fa: F[A], f: <=>[A, B], g: <=>[B, C])(implicit equal: Equal[F[C]]): Boolean

    Permalink
    Definition Classes
    Invariant
  10. final def contramapSubset[A, B](f: (B) ⇒ A)(implicit arg0: AnyType[B]): (F[A]) ⇒ F[B]

    Permalink
    Definition Classes
    ContravariantContravariantSubset
  11. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  13. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  15. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  16. def identityLaw1[A](fa: F[A])(implicit equal: Equal[F[A]]): Boolean

    Permalink
    Definition Classes
    Invariant
  17. final def invmap[A, B](f: <=>[A, B]): <=>[F[A], F[B]]

    Permalink
    Definition Classes
    ContravariantInvariant
  18. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  19. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  20. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  21. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  22. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  23. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  24. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Invariant[F]

Inherited from ContravariantSubset[F, AnyType]

Inherited from AnyRef

Inherited from Any

Ungrouped