Skip to content

Latest commit

 

History

History
39 lines (33 loc) · 846 Bytes

getting_started.md

File metadata and controls

39 lines (33 loc) · 846 Bytes

Enum-FP

Functional enum type for javascript with pattern matching

Read more about SumTypes using EnumFP in this blog post

Getting started

To add this package to your project

yarn add enum-fp

Or if you are one of those npm or pnpm nuts

npm i --save enum-fp
pnpm i --save enum-fp

Import it to your file

import Enum from 'enum-fp';

Create an enum type

const Action = Enum([ 'Add', 'Edit', 'Delete', 'Get' ]);

// Or with a fixed number of arguments
const Maybe = Enum({
    Just: [ 'value' ],
    Nothing: [],
});

Create an instance of the type using one of the contructors

const action = Action.Edit(2, 'Hello world');

Next topic >