Add syntax for sequential operations with `Parallel`
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
At the moment there are a few combinators leveraging Parallel instances, that allow using parallel applicative operations with monadic values (parAp and so on). However, there are none that allow using monadic operation with applicative values. This is a problem in a context where applicative is the default mode of operation.
Consider Validated. When we need sequential logic, we have three choices:
- Use
andThencombinator. This works, but it is overly specific - it obviously doesn't work with transformers, even though there are corresponding liftedParallelinstances. - Use
Parallel.sequentialandParallel.paralleldirectly. This works, but it is rather noisy (we need three more function calls for a single.flatMap). - Use
Eitherinstead, and make all the parallel operations explicit. This is inconvenient when our logic is mostly parallel - we have to avoid using most instances (ApplicativeandSemigroupforEitherwill lose errors).
Instead, I propose we add some combinators and syntax that will wrap the corresponding monadic operations:
def seqFlatMap[F[_], M[_], A, B](fa: F[A])(f: A => F[B])(implicit p: ParallelNonEmpty[M, F]): F[B]
def seqFlatten[F[_], M[_], A](ffa: F[F[A]])(implicit p: ParallelNonEmpty[M, F]): F[A]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing parAp combinators, Parallel.sequential and Parallel.parallel, and the related ParallelNonEmpty instances. Define the scope around the proposed seqFlatMap and seqFlatten operations and their syntax; done means sequential operations are available for applicative values without the direct Parallel calls described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100