Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved MonoidK docs #3501

Merged
merged 4 commits into from
Jul 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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