diff --git a/docs/src/main/tut/typeclasses/applicative.md b/docs/src/main/tut/typeclasses/applicative.md index 4c6cea3ef5..bf888b47fc 100644 --- a/docs/src/main/tut/typeclasses/applicative.md +++ b/docs/src/main/tut/typeclasses/applicative.md @@ -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.