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

Document Parallel type class, parSequence, parTraverse, and parMapN #103

Open
davegurnell opened this issue Dec 14, 2017 · 0 comments
Open

Comments

@davegurnell
Copy link
Contributor

Parallel is a type class that maps monads to equivalent applicatives. For example, there is an instance of Parallel to map between instances of Either and Validated.

There seem to be three key bits of syntax related to Parallel: parMapN, parSequence, and parTraverse. These combine instances of the monad by converting them to the equivalent applicative and back again:

import cats.instances.list._ // for Monoid
import cats.instances.parallel._ // for Parallel
import cats.syntax.parallel._

val either1: Either[List[String], Int] = Left(List("error1"))
val either2: Either[List[String], Int] = Left(List("error2"))
val either3: Either[List[String], Int] = Left(List("error3"))

(either1, either2, either3).parMapN(_ + _ + _)
// Left(List("error1", "error2", "error3"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant