I have a pipe that return Either<Error, Task<any>> but what I need is TaskEither<Error, any>.
How can I convert Either<Error, Task<any>> to TaskEither<Error, any>?
Is there any helper any utility function for doing this?
That's sequence
declare const a: E.Either<Error, T.Task<unknown>>;
const b: TE.TaskEither<Error, unknown> = E.either.sequence(T.task)(a);
@giogonzo When I copy paste the sequence example above and leave out the explicit type of b, its type is inferred as Task<Either<Error, unknown>>.
So, is Task<Either<Error, unknown>> intended to be and stay the same as TaskEither<Error, unknown> in the API?
@ford04 I omitted the part "given how a TaskEither is represented" in my previous answer.
It is definitely intended to be this way today, and for what I can tell also intended to stay the same.
This is actually an advantage of the current class-less / naked datatype encoding.
Similarly, you can do things like
// collect all successes AND failures:
A.array.sequence(T.task)(arrayOfTaskEithers)
// fail if some failure is encountered:
A.array.sequence(TE.taskEither)(arrayOfTaskEithers)
In any case, I don't see this as a major concern: with proper type annotations in place, if this ever changes, you'll be able to fix the error by providing a different implementation for such transformation
Most helpful comment
That's
sequence