unsplash / sum-types

Safe, ergonomic, non-generic sum types in TypeScript.
https://unsplash.github.io/sum-types/
MIT License
42 stars 2 forks source link

Match constant #49

Closed samhh closed 1 year ago

samhh commented 1 year ago

The following is quite common, particularly for nullary sums:

Sum.match({
  // Or lambdas, similar verbosity.
  Foo: constant('foo'),
  Bar: constant('bar'),
  Baz: constant('baz'),
})

We could add match/matchW variants that don't provide access to member values:

Sum.matchConstantButPleaseRenameMe({
  Foo: 'foo',
  Bar: 'bar',
  Baz: 'baz',
})
samhh commented 1 year ago

matchX - "X" like "strict".