Implementing Promise.allSettled
#1754
Answered
by
gcanti
THOUSAND-SKY
asked this question in
Q&A
-
I was looking for a way to replicating Here is a small starter
Also how about using the github wiki and making it public editable? Recipes such as these might be kept up to date with a lower barrier of entry, then. |
Beta Was this translation helpful? Give feedback.
Answered by
gcanti
Aug 31, 2022
Replies: 1 comment 1 reply
-
import { array, task, taskEither } from 'fp-ts'
import { pipe } from 'fp-ts/function'
;(async () => {
console.log(
await pipe(
[1, 2, 3, 4],
array.map((x) =>
x > 2 ? taskEither.left<number, number>(x) : taskEither.right(x)
),
array.sequence(task.ApplicativePar)
)()
)
})() p.s. Note that import { array, task, taskEither } from 'fp-ts'
import { pipe } from 'fp-ts/function'
;(async () => {
console.log(
await pipe(
[1, 2, 3, 4],
array.traverse(task.ApplicativePar)((x) =>
x > 2 ? taskEither.left<number, number>(x) : taskEither.right(x)
)
)()
)
})() |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
THOUSAND-SKY
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
p.s.
Note that
map + sequence = traverse