Packages

trait MonoidK[F[_]] extends SemigroupK[F]

MonoidK is a universal monoid which operates on kinds.

This type class is useful when its type parameter F[_] has a structure that can be combined for any particular type, and which also has an "empty" representation. Thus, MonoidK is like a Monoid for kinds (i.e. parametrized types).

A MonoidK[F] can produce a Monoid[F[A]] for any type A.

Here's how to distinguish Monoid and MonoidK:

  • Monoid[A] allows A values to be combined, and also means there is an "empty" A value that functions as an identity.
  • MonoidK[F] allows two F[A] values to be combined, for any A. It also means that for any A, there is an "empty" F[A] value. The combination operation and empty value just depend on the structure of F, but not on the structure of A.
Self Type
MonoidK[F]
Source
MonoidK.scala
Linear Supertypes
Known Subclasses
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. MonoidK
  2. SemigroupK
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def combineK[A](x: F[A], y: F[A]): F[A]

    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
  2. abstract def empty[A]: F[A]

    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()

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. 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
    MonoidKSemigroupK
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  7. def combineAllK[A](as: IterableOnce[F[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()
  8. def combineAllOptionK[A](as: IterableOnce[F[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
    Definition Classes
    SemigroupK
  9. def combineKEval[A](x: F[A], y: Eval[F[A]]): Eval[F[A]]

    Similar to combineK but uses Eval to allow for laziness in the second argument.

    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)
    Definition Classes
    SemigroupK
  10. def combineNK[A](a: F[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
    MonoidKSemigroupK
  11. 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
    MonoidKSemigroupK
  12. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  14. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  15. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  16. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  17. def isEmpty[A](a: F[A])(implicit ev: Eq[F[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
  18. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  19. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  21. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. def repeatedCombineNK[A](a: F[A], n: Int): F[A]

    Return a combined with itself more than once.

    Return a combined with itself more than once.

    Attributes
    protected[this]
    Definition Classes
    SemigroupK
  23. 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
    MonoidKSemigroupK
  24. def sum[A, B](fa: F[A], fb: F[B])(implicit F: Functor[F]): 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))
    Definition Classes
    SemigroupK
  25. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  26. def toString(): String
    Definition Classes
    AnyRef → Any
  27. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  28. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  29. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from SemigroupK[F]

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped