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

Add a few examples for MonoidK #1383

Merged
merged 2 commits into from
Oct 19, 2016
Merged
Changes from 1 commit
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
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.instances.list._
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #1026 we settled on using the "uber import" (import cats.implicits._) in the documentation. For the rest 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I didn't know that. Fixed.

```

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.