Björn Pattern Matching
Björn is a JavaScript native array pattern matcher that uses predicates to find sequences within sequences. It gives you practical and no-bloat no-bullshit pattern matching over arrays.
Installation
npm install bjorn
Usage
const bjorn = require("bjorn");
Examples
Björn finds arrays within arrays:
const bjorn = const p0 = x === 0;const p1 = x === 1;const p2 = x === 2; const seq = 0 1 2 3 4 5 6 7 8 9; p0 p1 p2 console;// 0, [3, 4, 5, 6, 7, 8, 9]
Björn can find them with or without seeking:
const one = x === 1;const two = x === 2; // default (start at input 0)const onetwo = one a b;// undefined // seek:true means read input until a match is foundconst onetwo = one a b;// [1, 2]