trait SemigroupK[F[_]] extends Serializable
SemigroupK is a universal semigroup 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. Thus, SemigroupK is like a Semigroup for kinds (i.e. parametrized types).
A SemigroupK[F] can produce a Semigroup[F[A]] for any type A.
Here's how to distinguish Semigroup and SemigroupK:
- Semigroup[A] allows two A values to be combined.
- SemigroupK[F] allows two F[A] values to be combined, for any A. The combination operation just depends on the structure of F, but not the structure of A.
- Self Type
- SemigroupK[F]
- Source
- SemigroupK.scala
- Alphabetic
- By Inheritance
- SemigroupK
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- 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)
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
- def algebra[A]: Semigroup[F[A]]
Given a type A, create a concrete
Semigroup[F[A]]
.Given a type A, create a concrete
Semigroup[F[A]]
.Example:
scala> import cats.implicits._ scala> val s: Semigroup[List[Int]] = SemigroupK[List].algebra[Int]
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- 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
- 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, butcombineKEval
"short-circuits" the computation.x
isSome
and thus the result ofbomb
doesn't even need to be evaluated in order to determine that the result ofcombineKEval
should bex
.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)
- def combineNK[A](a: F[A], n: Int): F[A]
Return
a
combined with itselfn
times.Return
a
combined with itselfn
times.Example:
scala> SemigroupK[List].combineNK(List(1), 5) res0: List[Int] = List(1, 1, 1, 1, 1)
- def compose[G[_]]: SemigroupK[[α]F[G[α]]]
"Compose" with a
G[_]
type to form aSemigroupK
forλ[α => F[G[α]]]
."Compose" with a
G[_]
type to form aSemigroupK
forλ[α => F[G[α]]]
. Note that this universally works for anyG
, because the "inner" structure isn't considered when combining two instances.Example:
scala> import cats.implicits._ scala> type ListOption[A] = List[Option[A]] scala> val s: SemigroupK[ListOption] = SemigroupK[List].compose[Option] scala> s.combineK(List(Some(1), None, Some(2)), List(Some(3), None)) res0: List[Option[Int]] = List(Some(1), None, Some(2), Some(3), None)
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- 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()
- 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]
- def reverse: SemigroupK[F]
return a semigroupK that reverses the order so combineK(a, b) == reverse.combineK(b, a)
- def sum[A, B](fa: F[A], fb: F[B])(implicit F: Functor[F]): F[Either[A, B]]
Combines
F[A]
andF[B]
into aF[Either[A,B]]]
.Combines
F[A]
andF[B]
into aF[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))
- 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(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()