Skip to content

Commit

Permalink
Merge pull request #1383 from cb372/monoidk-examples
Browse files Browse the repository at this point in the history
Add a few examples for MonoidK
  • Loading branch information
peterneyens committed Oct 19, 2016
2 parents 86491ba + 87a9da2 commit a7a6389
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/src/main/tut/monoidk.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.implicits._
```

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.

0 comments on commit a7a6389

Please sign in to comment.