catsInstances

object catsInstances extends ContravariantMonoidal[Observer] with MonoidK[Observer]
trait MonoidK[Observer]
trait SemigroupK[Observer]
trait ContravariantMonoidal[Observer]
trait InvariantMonoidal[Observer]
trait ContravariantSemigroupal[Observer]
trait Contravariant[Observer]
trait InvariantSemigroupal[Observer]
trait Invariant[Observer]
trait Semigroupal[Observer]
trait Serializable
class Object
trait Matchable
class Any

Value members

Concrete methods

override def combineK[T](a: Observer[T], b: Observer[T]): Observer[T]

Combine two F[A] values.

Combine two F[A] values.

Example:

scala> import cats.implicits._
scala> SemigroupK[List].combineK(List(1, 2), List(3, 4))
res0: List[Int] = List(1, 2, 3, 4)
Definition Classes
SemigroupK
override def contramap[A, B](fa: Observer[A])(f: B => A): Observer[B]
Definition Classes
Contravariant
override def empty[T]: Observer[T]

Given a type A, create an "empty" F[A] value.

Given a type A, create an "empty" F[A] value.

Example:

scala> import cats.implicits._
scala> MonoidK[List].empty[Long]
res0: List[Long] = List()
Definition Classes
MonoidK
override def product[A, B](fa: Observer[A], fb: Observer[B]): Observer[(A, B)]

Combine an F[A] and an F[B] into an F[(A, B)] that maintains the effects of both fa and fb.

Combine an F[A] and an F[B] into an F[(A, B)] that maintains the effects of both fa and fb.

Example:

scala> import cats.implicits._

scala> val noneInt: Option[Int] = None
scala> val some3: Option[Int] = Some(3)
scala> val noneString: Option[String] = None
scala> val someFoo: Option[String] = Some("foo")

scala> Semigroupal[Option].product(noneInt, noneString)
res0: Option[(Int, String)] = None

scala> Semigroupal[Option].product(noneInt, someFoo)
res1: Option[(Int, String)] = None

scala> Semigroupal[Option].product(some3, noneString)
res2: Option[(Int, String)] = None

scala> Semigroupal[Option].product(some3, someFoo)
res3: Option[(Int, String)] = Some((3,foo))
Definition Classes
Semigroupal
override def unit: Observer[Unit]
Definition Classes
InvariantMonoidal

Inherited methods

override def algebra[A]: Monoid[F[A]]

Given a type A, create a concrete Monoid[F[A]].

Given a type A, create a concrete Monoid[F[A]].

Example:

scala> import cats.implicits._
scala> MonoidK[List].algebra[Long].empty
res0: List[Long] = List()
Definition Classes
MonoidK -> SemigroupK
Inherited from:
MonoidK
def combineAllK[A](as: IterableOnce[Observer[A]]): F[A]

Given a sequence of as, sum them using the monoidK and return the total.

Given a sequence of as, sum them using the monoidK and return the total.

Example:

scala> MonoidK[List].combineAllK(List(List("One"), List("Two"), List("Three")))
res0: List[String] = List(One, Two, Three)

scala> MonoidK[List].combineAllK[String](List.empty)
res1: List[String] = List()
Inherited from:
MonoidK
def combineAllOptionK[A](as: IterableOnce[Observer[A]]): Option[F[A]]

Given a sequence of as, combine them and return the total.

Given a sequence of as, combine them and return the total.

If the sequence is empty, returns None. Otherwise, returns Some(total).

Example:

scala> SemigroupK[List].combineAllOptionK(List(List("One"), List("Two"), List("Three")))
res0: Option[List[String]] = Some(List(One, Two, Three))

scala> SemigroupK[List].combineAllOptionK[String](List.empty)
res1: Option[List[String]] = None
Inherited from:
SemigroupK
def combineKEval[A](x: Observer[A], y: Eval[Observer[A]]): Eval[F[A]]

Similar to combineK but uses Eval to allow for laziness in the second argument. This can allow for "short-circuiting" of computations.

Similar to combineK but uses Eval to allow for laziness in the second argument. This can allow for "short-circuiting" of computations.

NOTE: the default implementation of combineKEval does not short-circuit computations. For data structures that can benefit from laziness, SemigroupK instances should override this method.

In the following example, x.combineK(bomb) would result in an error, but combineKEval "short-circuits" the computation. x is Some and thus the result of bomb doesn't even need to be evaluated in order to determine that the result of combineKEval should be x.

scala> import cats.{Eval, Later}
scala> import cats.implicits._
scala> val bomb: Eval[Option[Int]] = Later(sys.error("boom"))
scala> val x: Option[Int] = Some(42)
scala> x.combineKEval(bomb).value
res0: Option[Int] = Some(42)
Inherited from:
SemigroupK
override def combineNK[A](a: Observer[A], n: Int): F[A]

Return a combined with itself n times.

Return a combined with itself n times.

Example:

scala> SemigroupK[List].combineNK(List(1), 5)
res0: List[Int] = List(1, 1, 1, 1, 1)

scala> MonoidK[List].combineNK(List("ha"), 0)
res1: List[String] = List()

Definition Classes
MonoidK -> SemigroupK
Inherited from:
MonoidK
override def compose[G[_]]: MonoidK[[α] =>> F[G[α]]]

Given a kind G, create an "composed" MonoidK[F[G[_]]

Given a kind G, create an "composed" MonoidK[F[G[_]]

Example:

scala> import cats.implicits._
scala> val monoidK = MonoidK[List].compose[Option]
scala> monoidK.combineK(List(Some(1)), List(Some(2), None))
res0: List[Option[Int]] = List(Some(1), Some(2), None)
Definition Classes
MonoidK -> SemigroupK
Inherited from:
MonoidK
def compose[G[_] : Invariant]: Invariant[[α] =>> F[G[α]]]

Compose Invariant F[_] and G[_] then produce Invariant[F[G[_]]] using their imap.

Compose Invariant F[_] and G[_] then produce Invariant[F[G[_]]] using their imap.

Example:

scala> import cats.implicits._
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)
Inherited from:
Invariant
def compose[G[_] : Contravariant]: Functor[[α] =>> F[G[α]]]
Inherited from:
Contravariant
def composeApply[G[_] : Apply]: InvariantSemigroupal[[α] =>> F[G[α]]]
Inherited from:
InvariantSemigroupal
def composeContravariant[G[_] : Contravariant]: Invariant[[α] =>> F[G[α]]]

Compose Invariant F[_] and Contravariant G[_] then produce Invariant[F[G[_]]] using F's imap and G's contramap.

Compose Invariant F[_] and Contravariant G[_] then produce Invariant[F[G[_]]] using F's imap and G's contramap.

Example:

scala> import cats.implicits._
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
Inherited from:
Invariant
override def composeFunctor[G[_] : Functor]: ContravariantSemigroupal[[α] =>> F[G[α]]]

Compose Invariant F[_] and Functor G[_] then produce Invariant[F[G[_]]] using F's imap and G's map.

Compose Invariant F[_] and Functor G[_] then produce Invariant[F[G[_]]] using F's imap and G's map.

Example:

scala> import cats.implicits._
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
ContravariantSemigroupal -> Contravariant -> Invariant
Inherited from:
ContravariantSemigroupal
override def imap[A, B](fa: Observer[A])(f: A => B)(fi: B => A): F[B]

Transform an F[A] into an F[B] by providing a transformation from A to B and one from B to A.

Transform an F[A] into an F[B] by providing a transformation from A to B and one from B to A.

Example:

scala> import cats.implicits._
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
Inherited from:
Contravariant
def isEmpty[A](a: Observer[A])(implicit ev: Eq[Observer[A]]): Boolean

Tests if a is the identity.

Tests if a is the identity.

Example:

scala> MonoidK[List].isEmpty(List.empty[String])
res0: Boolean = true

scala> MonoidK[List].isEmpty(List("something"))
res1: Boolean = false
Inherited from:
MonoidK
def liftContravariant[A, B](f: A => B): F[B] => F[A]
Inherited from:
Contravariant
def narrow[A, B <: A](fa: Observer[A]): F[B]

Lifts natural subtyping contravariance of contravariant Functors. could be implemented as contramap(identity), but the Functor laws say this is equivalent

Lifts natural subtyping contravariance of contravariant Functors. could be implemented as contramap(identity), but the Functor laws say this is equivalent

Inherited from:
Contravariant
def point[A](a: A): F[A]

point lifts any value into a Monoidal Functor.

point lifts any value into a Monoidal Functor.

Example:

scala> import cats.implicits._

scala> InvariantMonoidal[Option].point(10)
res0: Option[Int] = Some(10)
Inherited from:
InvariantMonoidal
override def reverse: MonoidK[F]

return a semigroupK that reverses the order so combineK(a, b) == reverse.combineK(b, a)

return a semigroupK that reverses the order so combineK(a, b) == reverse.combineK(b, a)

Definition Classes
MonoidK -> SemigroupK
Inherited from:
MonoidK
def sum[A, B](fa: Observer[A], fb: Observer[B])(implicit F: Functor[Observer]): F[Either[A, B]]

Combines F[A] and F[B] into a F[Either[A,B]]].

Combines F[A] and F[B] into a F[Either[A,B]]].

Example:

scala> import cats.SemigroupK
scala> import cats.data.NonEmptyList
scala> SemigroupK[NonEmptyList].sum(NonEmptyList.one("abc"), NonEmptyList.one(2))
res0: NonEmptyList[Either[String,Int]] = NonEmptyList(Left(abc), Right(2))
Inherited from:
SemigroupK
def trivial[A]: F[A]

trivial produces an instance of F for any type A that is trivial with respect to contramap2 along the diagonal

trivial produces an instance of F for any type A that is trivial with respect to contramap2 along the diagonal

Inherited from:
ContravariantMonoidal