-
-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sequence EitherT #79
Comments
Yes but with some work: import * as task from 'fp-ts/lib/Task'
import * as either from 'fp-ts/lib/Either'
import * as eitherT from 'fp-ts/lib/EitherT'
import * as array from 'fp-ts/lib/Array'
import * as traversable from 'fp-ts/lib/Traversable'
const allsuccess = [
either.right<string, number>(1),
either.right<string, number>(2),
either.right<string, number>(3)
]
.map(task.of)
.map(t => new eitherT.EitherT(task, t))
const eitherTApplicative = {
URI: eitherT.URI as eitherT.URI,
of: eitherT.of(task),
map<L, A, B>(f: (a: A) => B, fa: eitherT.EitherT<task.URI, L, A>) {
return eitherT.map(f, fa)
},
ap<L, A, B>(fab: eitherT.EitherT<task.URI, L, (a: A) => B>, fa: eitherT.EitherT<task.URI, L, A>) {
return eitherT.ap(fab, fa)
}
}
const x: eitherT.EitherT<task.URI, string, number[]> = traversable.sequence(eitherTApplicative, array)(allsuccess)
x.value.run().then(y => console.log(y)) // Right([1,2,3]) Now writing const eitherTApplicative = eitherT.getStaticMonad(task) |
|
I am trying to sequence an array of
EitherT
:However, I get this error:
Should this be possible?
For context, I have a bunch of tasks that I want to fire of in parallel, but as soon as one of them fails, I want to respond with that failure immediately—instead of waiting for the other tasks to finish and then sequencing the results.
This would be similar to
Promise.all
, which will return a rejected promise as soon as one of the promises is rejected.The text was updated successfully, but these errors were encountered: