monoidK
Value members
Concrete methods
Inherited methods
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
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
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
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