paldepind / union-type

A small JavaScript library for defining and using union types.
MIT License
477 stars 28 forks source link

Add case and caseOn as instance methods for types #44

Closed pelotom closed 8 years ago

pelotom commented 8 years ago

Add instance methods for case and caseOn so you can do e.g.

const { Just, Nothing } = Type({
  Just: [T],
  Nothing: []
})

const m = Just(3)

m.case({
  Nothing: () => 0,
  Just: (n) => n + 2
})
paldepind commented 8 years ago

Thank you. It seems sensible.