Add a Variant module, for construction of and destructuring of general ADTS
See original GitHub issueš 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.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
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:
NB thereās also sum-types.