Skip to content

Given an array of TaskEither, what's the best way to run them all in parallel and collect all Left and Right? #1730

Answered by 0x706b
evelant asked this question in Q&A
Discussion options

You must be logged in to vote

You could use wilt from the Witherable typeclass (basically an effectful partitionMap):

import { pipe, identity } from 'fp-ts/function'
import * as T from 'fp-ts/Task'
import * as TE from 'fp-ts/TaskEither'
import * as RA from 'fp-ts/ReadonlyArray'

declare const effects: ReadonlyArray<TE.TaskEither<Error, string>>

pipe(
  effects,
  RA.wilt(T.ApplicativePar)(identity),
)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@evelant
Comment options

Answer selected by evelant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants