flatMap deep chained Either-functions calls with fp-ts

48 Views Asked by At

is there a way to implement a deep record of async functions returning Eithers in such a way that a deep chained call finally returns the appropriate widened Either ?

// this doesn't work
// but I hope it makes the idea

declare function a(): Either<ErrA, {
      b(): Either<ErrB, {
        c(): Either<ErrC, string>
      }>
    }
  >

const result = a().b().c() // Either<ErrA | ErrB | ErrC, string>

just like a pipe( ...flatMap() ) would do.

my actual use case would have asyncrounous return types at each step, and the ideal api would look as follows:

const result = await a().b().c() 
// result: E.Either<ErrA | ErrB | ErrC, string>
0

There are 0 best solutions below