Skip to content

Commit

Permalink
Merge pull request #4269 from benhutchison/patch-3
Browse files Browse the repository at this point in the history
Mention `tupled` syntax, a Cats workhorse that deserves to be more well known
  • Loading branch information
armanbilge authored Jul 13, 2022
2 parents e584984 + 70060fe commit f8f6eff
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/typeclasses/applicative.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,20 @@ import cats.implicits._
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.

Another very useful `Apply` syntax is `tupled`, which allows a tuple of effectful values to be composed into a single effectful value containing a tuple.

```scala mdoc
import cats.implicits._

val optPair: Option[(String, String)] = (username, password).tupled
```

### See also Parallel variants

Both `tupled` and `mapN` have [parallel](parallel.md) variant operations, named `parTupled` and `parMapN` respectively. Regular `tupled`/`mapN` evaluate their effects from left to right ("sequentially"), while `parTupled`/`parMapN` evaluate in an indeterminate order, or in parallel.

The difference can be understood intuitively when the effect is an executable task, such as `IO` from [Cats Effect](https://typelevel.org/cats-effect/docs/concepts#concurrent). In this case, the parallel variants enable you to compose tuples of tasks into a single task that will run its sub-tasks concurrently.

## Further Reading

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

0 comments on commit f8f6eff

Please sign in to comment.