Skip to content

Add a Variant module, for construction of and destructuring of general ADTS #1770

@rachel-barrett

Description

@rachel-barrett

🚀 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions