matier

0.0.1 • Public • Published

matier

Run functions on matched expressions.

class Just {
  constructor(value) { this.value = value; }
}
class Nothing {}
 
const maybe =
  (thing) =>
    thing ? new Just(thing) : new Nothing();
 
const res = match(
  maybe(10), [
    (x) => x instanceof Just,
    (jx) => {
      console.log(`is Just ${jx.value}`);
      return jx.value;
    },
  ], [
    (x) => x instanceof Nothing,
    (n) => console.log('is nothing'),
  ]
)
 
console.log(res); // 10

Getting Started

Install with npm:

npm install matier

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i matier

      Weekly Downloads

      0

      Version

      0.0.1

      License

      ISC

      Unpacked Size

      1.88 kB

      Total Files

      4

      Last publish

      Collaborators

      • gsantos