Covariant

zio.prelude.Covariant
See theCovariant companion object
trait Covariant[F[_]] extends CovariantSubset[F, AnyType], Invariant[F]

Covariant[F] provides implicit evidence that F[+_] is a covariant endofunctor in the category of Scala objects.

Covariant instances of type F[A] "produce" values of type A in some sense. In some cases, such as with a List[A], this means that they contain values of type A, in which case we can simply access the elements of the collection. In other cases it means that output values of type A which may not already exists, such as with a Function0[A] that produces A values when invoked.

Common examples of covariant instances in ZIO includes effects with respect to their error and value types, sinks with respect to their error and output types, and queues and references with respect to their error and output types.

Covariant instances support a map operation which allows transforming the output type given a function from the old output type to the new output type. For example, if we have a List[String] and a function String => Int that returns the length of a string, then we can construct a List[Int] with the length of each string.

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 map[A, B](f: A => B): (F[A]) => F[B]

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

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

Attributes

Concrete methods

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

Compose two covariant functors.

Compose two covariant functors.

Attributes

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

Compose covariant and contravariant functors.

Compose covariant and contravariant functors.

Attributes

def fproduct[A, B](f: A => B): (F[A]) => F[(A, B)]
def fproductLeft[A, B](f: A => B): (F[A]) => F[(B, A)]
final def invmap[A, B](f: Equivalence[A, B]): Equivalence[F[A], F[B]]
final def mapSubset[A, B : AnyType](f: A => B): (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