Skip to content

Commit

Permalink
improved MonoidK docs (#3501)
Browse files Browse the repository at this point in the history
* add MonoidK#algebra doc

* add compose doc

* add type

* fix doctest
  • Loading branch information
kazchimo authored Jul 5, 2020
1 parent b36ab72 commit 714f0da
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion core/src/main/scala/cats/MonoidK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,34 @@ import scala.annotation.implicitNotFound

/**
* 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()
* }}}
*/
override def algebra[A]: Monoid[F[A]] =
new Monoid[F[A]] {
def empty: F[A] = self.empty
def combine(x: F[A], y: F[A]): F[A] = self.combineK(x, y)
}

/**
* 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)
* }}}
*/
override def compose[G[_]]: MonoidK[λ[α => F[G[α]]]] =
new ComposedMonoidK[F, G] {
val F = self
val F: MonoidK[F] = self
}
}

Expand Down

0 comments on commit 714f0da

Please sign in to comment.