trait Contravariant[F[_]] extends Invariant[F]
Must obey the laws defined in cats.laws.ContravariantLaws.
- Self Type
- Contravariant[F]
- Source
- Contravariant.scala
- Alphabetic
- By Inheritance
- Contravariant
- Invariant
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
- abstract def contramap[A, B](fa: F[A])(f: (B) ⇒ A): F[B]
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
- def compose[G[_]](implicit arg0: Contravariant[G]): Functor[[α]F[G[α]]]
-
def
compose[G[_]](implicit arg0: Invariant[G]): Invariant[[α]F[G[α]]]
Compose Invariant
F[_]
andG[_]
then produceInvariant[F[G[_]]]
using theirimap
.Compose Invariant
F[_]
andG[_]
then produceInvariant[F[G[_]]]
using theirimap
.Example:
scala> import cats.syntax.all._ scala> import scala.concurrent.duration._ scala> val durSemigroupList: Semigroup[List[FiniteDuration]] = | Invariant[Semigroup].compose[List].imap(Semigroup[List[Long]])(Duration.fromNanos)(_.toNanos) scala> durSemigroupList.combine(List(2.seconds, 3.seconds), List(4.seconds)) res1: List[FiniteDuration] = List(2 seconds, 3 seconds, 4 seconds)
- Definition Classes
- Invariant
-
def
composeContravariant[G[_]](implicit arg0: Contravariant[G]): Invariant[[α]F[G[α]]]
Compose Invariant
F[_]
and ContravariantG[_]
then produceInvariant[F[G[_]]]
using F'simap
and G'scontramap
.Compose Invariant
F[_]
and ContravariantG[_]
then produceInvariant[F[G[_]]]
using F'simap
and G'scontramap
.Example:
scala> import cats.syntax.all._ scala> import scala.concurrent.duration._ scala> type ToInt[T] = T => Int scala> val durSemigroupToInt: Semigroup[ToInt[FiniteDuration]] = | Invariant[Semigroup] | .composeContravariant[ToInt] | .imap(Semigroup[ToInt[Long]])(Duration.fromNanos)(_.toNanos) // semantically equal to (2.seconds.toSeconds.toInt + 1) + (2.seconds.toSeconds.toInt * 2) = 7 scala> durSemigroupToInt.combine(_.toSeconds.toInt + 1, _.toSeconds.toInt * 2)(2.seconds) res1: Int = 7
- Definition Classes
- Invariant
-
def
composeFunctor[G[_]](implicit arg0: Functor[G]): Contravariant[[α]F[G[α]]]
Compose Invariant
F[_]
and FunctorG[_]
then produceInvariant[F[G[_]]]
using F'simap
and G'smap
.Compose Invariant
F[_]
and FunctorG[_]
then produceInvariant[F[G[_]]]
using F'simap
and G'smap
.Example:
scala> import cats.syntax.all._ scala> import scala.concurrent.duration._ scala> val durSemigroupList: Semigroup[List[FiniteDuration]] = | Invariant[Semigroup] | .composeFunctor[List] | .imap(Semigroup[List[Long]])(Duration.fromNanos)(_.toNanos) scala> durSemigroupList.combine(List(2.seconds, 3.seconds), List(4.seconds)) res1: List[FiniteDuration] = List(2 seconds, 3 seconds, 4 seconds)
- Definition Classes
- Contravariant → Invariant
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
imap[A, B](fa: F[A])(f: (A) ⇒ B)(fi: (B) ⇒ A): F[B]
Transform an
F[A]
into anF[B]
by providing a transformation fromA
toB
and one fromB
toA
.Transform an
F[A]
into anF[B]
by providing a transformation fromA
toB
and one fromB
toA
.Example:
scala> import cats.syntax.all._ scala> import scala.concurrent.duration._ scala> val durSemigroup: Semigroup[FiniteDuration] = | Invariant[Semigroup].imap(Semigroup[Long])(Duration.fromNanos)(_.toNanos) scala> durSemigroup.combine(2.seconds, 3.seconds) res1: FiniteDuration = 5 seconds
- Definition Classes
- Contravariant → Invariant
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def liftContravariant[A, B](f: (A) ⇒ B): (F[B]) ⇒ F[A]
-
def
narrow[A, B <: A](fa: F[A]): F[B]
Lifts natural subtyping contravariance of contravariant Functors.
Lifts natural subtyping contravariance of contravariant Functors. could be implemented as contramap(identity), but the Functor laws say this is equivalent
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()