From 17c9e3efa2d6a293388b507cd162f58e651eb828 Mon Sep 17 00:00:00 2001 From: Chris Birchall Date: Tue, 20 Sep 2016 23:17:54 +0100 Subject: [PATCH 1/2] Add a few examples for MonoidK --- docs/src/main/tut/monoidk.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/src/main/tut/monoidk.md b/docs/src/main/tut/monoidk.md index 715f97b89c..b4d661905a 100644 --- a/docs/src/main/tut/monoidk.md +++ b/docs/src/main/tut/monoidk.md @@ -25,3 +25,37 @@ Here's how to distinguish `Monoid` and `MonoidK`: also means that for any `A`, there is an "empty" `F[A]` value. The combination operation and empty value just depend on the structure of `F`, but not on the structure of `A`. + +Let's compare the usage of `Monoid[A]` and `MonoidK[F]`. + +First some imports: + +```tut:silent +import cats.{Monoid, MonoidK} +import cats.instances.list._ +``` + +Just like `Monoid[A]`, `MonoidK[F]` has an `empty` method, but it is parameterized on the type of the element contained in `F`: + +```tut:book +Monoid[List[String]].empty +MonoidK[List].empty[String] +MonoidK[List].empty[Int] +``` + +And instead of `combine`, it has `combineK`, which also takes one type parameter: + +```tut:book +Monoid[List[String]].combine(List("hello", "world"), List("goodbye", "moon")) +MonoidK[List].combineK[String](List("hello", "world"), List("goodbye", "moon")) +MonoidK[List].combineK[Int](List(1, 2), List(3, 4)) +``` + +Actually the type parameter can usually be inferred: + +```tut:book +MonoidK[List].combineK(List("hello", "world"), List("goodbye", "moon")) +MonoidK[List].combineK(List(1, 2), List(3, 4)) +``` + +`MonoidK` extends [`SemigroupK`](semigroupk.html), so take a look at the `SemigroupK` documentation for more examples. From 87a9da2094758ada4eebb8dc3448657ddeb64944 Mon Sep 17 00:00:00 2001 From: Chris Birchall Date: Mon, 3 Oct 2016 11:31:09 +0200 Subject: [PATCH 2/2] Use uber import in documentation --- docs/src/main/tut/monoidk.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/main/tut/monoidk.md b/docs/src/main/tut/monoidk.md index b4d661905a..74250dc71e 100644 --- a/docs/src/main/tut/monoidk.md +++ b/docs/src/main/tut/monoidk.md @@ -32,7 +32,7 @@ First some imports: ```tut:silent import cats.{Monoid, MonoidK} -import cats.instances.list._ +import cats.implicits._ ``` Just like `Monoid[A]`, `MonoidK[F]` has an `empty` method, but it is parameterized on the type of the element contained in `F`: