Skip to content

mjgpy3/yapml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yapml

Yet another pattern matching library.

Examples

Dead-horse factorial

const on = require('yapml');

const factorial =
  on.value(1, () => 1).
  on.anything((n) => n * factorial(n - 1)).
  match;

console.log(factorial(5)); // => 120

Absolute value

const on = require('yapml');

const isNegative = (n) => n < 0;

const abs =
  on.satisfies(isNegative, (v) => -v).
  on.anything((n) => n).
  match;

console.log(abs(-42)); // => 42
console.log(abs(42)); // => 42

Why yet another?

yapml has a slightly different philosophy than those other pattern matching libraries. It strives to emphasize

Releases

No releases published

Packages

No packages published