fp-ts

Managing array of monads in fp-ts and Functional Programming

血红的双手。 提交于 2020-07-07 12:04:29
问题 I'm very new to Functional Programming and I'm struggling a lot with running traverse on arrays. When I read this book it seems that I should be able to simply traverse between Monads but I can't wrap my head around this concept with fp-ts. Can someone explain the following using array.traverse/sequence or any other ways please? How can I go from TaskEither<Error, string[]> to TaskEither<Error, Either<Error, string>[]> ; or is there a better way to go from a single error to nested errors

Running an array of TaskEithers in parallel, but continue if 1 or more task fails

久未见 提交于 2020-06-27 18:42:07
问题 I have to make an array of IO calls in parallel, and merge the contents of the call if successful. If one fails the others get processed as per normal, but an error message. My thought process on how this can be implemented: Array<TE<E, A>> -> TE<E, Array<A>> -> TE<E, MergedA> -> [E, A] What I'm currently doing: I am currently sequencing an array of TE, but any failure in the chain will yield a left. pipe( sequenceT(TE.taskEither)(arrayofTE), //TE<E,A>[] -> TE<E,A[]> TE.map(mergeFn), //TE<E,