typelevel / typelevel/cats

Add syntax for sequential operations with `Parallel`

Open
#2,958 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. Use andThen combinator. This works, but it is overly specific - it obviously doesn't work with transformers, even though there are corresponding lifted Parallel instances.
  2. Use Parallel.sequential and Parallel.parallel directly. This works, but it is rather noisy (we need three more function calls for a single .flatMap).
  3. Use Either instead, and make all the parallel operations explicit. This is inconvenient when our logic is mostly parallel - we have to avoid using most instances (Applicative and Semigroup for Either will 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.