Skip to content

Instantly share code, notes, and snippets.

@peter-wd-1
Last active November 24, 2022 04:21
Show Gist options
  • Save peter-wd-1/cf6c1dacf094e58439434fedd69a5baa to your computer and use it in GitHub Desktop.
Save peter-wd-1/cf6c1dacf094e58439434fedd69a5baa to your computer and use it in GitHub Desktop.
How to run multiple Task | TakeEither W/ argument for each of them.
import { sequenceT } from 'fp-ts/lib/Apply'
import { pipe } from 'fp-ts/lib/function'
import * as RTE from 'fp-ts/ReaderTaskEither'
import * as R from 'fp-ts/Reader'
import * as RA from 'fp-ts/ReadonlyArray'
import * as TE from 'fp-ts/TaskEither'
// (R) => TaskEither<e, r[]>
pipe(
'TestValue',
sequenceT(RTE.ApplicativeSeq)(
TE.left,
TE.right,
),
)().then(x=> console.log(x))
// TaskEither<e, r[]>
TE.sequenceArray([
TE.right(3),
TE.right(1)
])().then(x=>console.log(x))
pipe(
// TaskEither<e, r>[]
R.sequenceArray([
TE.right,
(a:any) => a === 1 ? TE.right(a) : TE.left(a),
])(2),
// you can filter right value.
RA.map(
pipe(
TE.map(x=>console.log(x))
)
),
TE.sequenceArray
)().then(x=>console.log(x))
// TaskEither<e, r[]>
sequenceT(TE.ApplySeq)(
TE.right(3),
TE.right(1)
)().then(x=>console.log(x))
@peter-wd-1
Copy link
Author

You can run multiple task that receive same argument. Try with right or left either task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment