diff --git a/core/src/main/scala/cats/MonoidK.scala b/core/src/main/scala/cats/MonoidK.scala index 621a0bc182..5e5c1b0823 100644 --- a/core/src/main/scala/cats/MonoidK.scala +++ b/core/src/main/scala/cats/MonoidK.scala @@ -26,6 +26,13 @@ import simulacrum.typeclass /** * Given a type A, create an "empty" F[A] value. + * + * Example: + * {{{ + * scala> import cats.implicits._ + * scala> MonoidK[List].empty[Long] + * res0: List[Long] = List() + * }}} */ def empty[A]: F[A] diff --git a/core/src/main/scala/cats/SemigroupK.scala b/core/src/main/scala/cats/SemigroupK.scala index 98164b0a79..f3ca1b5965 100644 --- a/core/src/main/scala/cats/SemigroupK.scala +++ b/core/src/main/scala/cats/SemigroupK.scala @@ -24,18 +24,45 @@ import simulacrum.typeclass /** * 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) + * }}} */ @simulacrum.op("<+>", alias = true) def combineK[A](x: F[A], y: F[A]): 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] + * }}} */ def algebra[A]: Semigroup[F[A]] = new Semigroup[F[A]] { def combine(x: F[A], y: F[A]): F[A] = self.combineK(x, y) } + /** + * "Compose" with a `G[_]` type to form a `SemigroupK` for `λ[α => F[G[α]]]`. + * Note that this universally works for any `G`, 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) + * }}} + */ def compose[G[_]]: SemigroupK[λ[α => F[G[α]]]] = new ComposedSemigroupK[F, G] { val F = self