-
-
Notifications
You must be signed in to change notification settings - Fork 504
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 a Variant module, for construction of and destructuring of general ADTS #1770
Comments
I definitely support the need for tooling like this. Whether or not it should be part of this library I can't say – for me, a standalone library works just as well and might allow to solve for different trade-offs. There are some libraries that work well with fp-ts: And now yours, which is nice and simple – thanks for that! |
Thanks for sharing those links! I wasn't aware of these libraries. |
NB there's also sum-types. |
I really like the idea of having a module to help with this - having to open a block for a case statement often looks out of place and gets on my nerves. |
Some of my thoughts on the advantages and disadvantages of Variant (or equivalent) being part of fp-ts: On the one hand I'm not sure that it fits in fp-ts since there's something slightly different about it as it doesn't follow the pattern of other modules. Also with variants not being native to typescript, it is harder to agree on a canonical way to implement them. On the other hand, things that make me think it makes sense in fp-ts:
|
I wouldn't necessarily semantically agree. There are multiple modules that represent product types, for example also |
🚀 Feature request
Desired Behavior
I think it would be good to have a module for helpers to construct Variant types (aka ADTs / Sum types / Discriminated unions) - the dual to Records. The advantage of such a module is that it reduces boiler plate and increases consistency when constructing algebraic data types.
The module would also have functions to apply functional pattern matching that doesn't rely on switch statements or the internals of the variant implementation.
Suggested Solution
I currently make use of my own library for this @rachel-barrett/variant-ts that I use alongside
fp-ts
, in both personal projects and at work. I think it could make sense for it to be a part of fp-ts. As far as I am aware there is not anything similar already in the fp-ts ecosystem?I have also written a pull request against fp-ts to illustrate more directly how it could fit in to fp-ts, which I will link.
Who does this impact? Who is this for?
This would be beneficial for all typescript users wanting to use algebraic data types in a functional style.
The text was updated successfully, but these errors were encountered: