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

Clean up applicative syntax doc #2036

Merged
merged 1 commit into from
Nov 23, 2017
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
27 changes: 12 additions & 15 deletions docs/src/main/tut/typeclasses/applicative.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,30 +251,27 @@ pair up (or apply functions to) values with the same key. Hence `Map[K, ?]` has
## Syntax

Syntax for `Applicative` (or `Apply`) is available under the `cats.implicits._` import. The most
interesting syntax is focused on composing independent effects - there are two options for this.
interesting syntax is focused on composing independent effects: it works just like the methods
for composition we saw above (`map3`, `tuple3`, etc.), but achieves a slightly friendlier syntax
by enriching Scala's standard tuple types.

The first is the builder syntax which incrementally builds up a collection of effects until a
function is applied to compose them.

```tut:book:silent
import cats.implicits._

val o1: Option[Int] = Some(42)
val o2: Option[String] = Some("hello")
```
For example, we've already seen this code for mapping over three options together:

```tut:book
(o1, o2).mapN((i: Int, s: String) => i.toString ++ s)
(o1, o2).tupled
Applicative[Option].map3(username, password, url)(attemptConnect)
```

The second expects the effects in a tuple and works by enriching syntax on top of the existing
`TupleN` types.
With the applicative syntax, we can change this to the slightly shorter:

```tut:book
(o1, o2).mapN((i: Int, s: String) => i.toString ++ s)
import cats.implicits._

(username, password, url).mapN(attemptConnect)
```

We don't have to mention the type or specify the number of values we're composing
together, so there's a little less boilerplate here.

## Further Reading

* [Applicative Programming with Effects][applicativePaper] - McBride, Patterson. JFP 2008.
Expand Down