0.0.23 • Published 4 years ago

bjorn v0.0.23

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

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 = require("bjorn")

const p0 = x => x === 0;
const p1 = x => x === 1;
const p2 = x => x === 2;

const seq = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

bjorn(seq)(
    [ p0, p1, p2, (p0, tail) => console.log(p0, tail)]
);
// 0, [3, 4, 5, 6, 7, 8, 9]

Björn can find them with or without seeking:

const one = x => x === 1;
const two = x => x === 2;

// default (start at input 0)
const onetwo = bjorn([0, 0, 0, 0, 1, 2, 3, 4])(
    [ one, two (a, b, tail) => [a, b]]
);
// undefined

// seek:true means read input until a match is found
const onetwo = bjorn([0, 0, 0, 0, 1, 2, 3, 4], { seek:true })(
    [ one, two (a, b, tail) => [a, b]]
);
// [1, 2]
0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago