Last active
November 24, 2022 04:21
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can run multiple task that receive same argument. Try with right or left either task.