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

Less strict version of match #70

Open
lauritzsh opened this issue Feb 14, 2023 · 1 comment · May be fixed by #110
Open

Less strict version of match #70

lauritzsh opened this issue Feb 14, 2023 · 1 comment · May be fixed by #110
Labels

Comments

@lauritzsh
Copy link

lauritzsh commented Feb 14, 2023

In a previous project I used fp-ts which has match and a less strict matchW (short for widening).

I'm not necessarily suggesting to add this (though it would be nice to have), but how would we implement this ourselves? I especially had trouble coming up with an implementation that supports both the data-first and data-last functionality.

function matchW<A, B, R, R2>(result: Result<A, B>, okFn: (value: A) => R, errorFn: (value: B) => R2): R | R2
function matchW<A, B, R, R2>(okFn: (value: A) => R, errorFn: (value: B) => R2): (result: Result<A, B>) => R | R2

The first one was pretty trivial to write, but did not manage to have one (at least clean) implementation supporting both. Is there an easy way to implement using match? Seeing an example would help me (and maybe others) understand how to implement similar helpers.

@JUSTIVE JUSTIVE linked a pull request Mar 11, 2024 that will close this issue
@JUSTIVE
Copy link
Sponsor

JUSTIVE commented Mar 11, 2024

Hi. I made a PR to resolve this issue. please have a look and let me know if it's right.

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

Successfully merging a pull request may close this issue.

3 participants