Skip to content
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

Add W-variants to Do, e.g. bindLW #64

Open
leemhenson opened this issue Jun 11, 2020 · 4 comments
Open

Add W-variants to Do, e.g. bindLW #64

leemhenson opened this issue Jun 11, 2020 · 4 comments

Comments

@leemhenson
Copy link

🚀 Feature request

Current Behavior

const foo = Do(TE.taskEither)
  .bind("te1", TE.right<boolean, number>(1))
  .bindL("te2", () => TE.right<string, string>("wat"));

fails with:

Type 'TaskEither<string, string>' is not assignable to type 'TaskEither<boolean, string>'.
Type 'string' is not assignable to type 'boolean'.ts(2322)

Desired Behavior

const foo = Do(TE.taskEither)
  .bind("te1", TE.right<boolean, number>(1))
  .bindLW("te2", () => TE.right<string, string>("wat"))
  .return(identity);

Where foo would be TaskEither<boolean | string, { te1: number} & { te2: string }>.

Suggested Solution

🤷‍♂️ Do is a complex beast.

Who does this impact? Who is this for?

This would alleviate the need to lift the first bind's Left into a union of all possible error types, which I believe is the current accepted workaround. This was the case for Either's chain too, until chainW was added recently. It would be great if we could get the same for Do.

@kirit0s
Copy link

kirit0s commented Jun 18, 2020

Can you give some examples how I can use different error types with Do notation without W-variants?

@kirit0s
Copy link

kirit0s commented Jun 18, 2020

Something like that?

type allErrors = Error1 | Error2;

Do(TE.taskEither)
  .bind(
    'result1',
    pipe(
      TE.right<Error1, number>(1),
      TE.mapLeft((err): allErrors => err),
    ),
  )
  .bind('result2', TE.right<Error2, number>(2));

@ghost
Copy link

ghost commented Nov 15, 2020

I too have encountered this problem. My errors are a union of string constants, and it would be nice to have a bindW and bindLW that would allow the error type of the Do(TE.taskEither to be the union of all error types in the Do.

@kirit0s
Copy link

kirit0s commented Nov 23, 2020

I recommend to use native fp-ts Do notaion - https://github.com/gcanti/fp-ts/releases/tag/2.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants