All Projects → fatih-erikli → pattern-case

fatih-erikli / pattern-case

Licence: other
Simple pattern matching in Typescript

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to pattern-case

go-pattern-match
Pattern matchings for Go.
Stars: ✭ 182 (+355%)
Mutual labels:  pattern-matching
lispy
Learning with Peter Norvig's lis.py interpreter
Stars: ✭ 133 (+232.5%)
Mutual labels:  pattern-matching
strings
String helper methods and an inflector
Stars: ✭ 31 (-22.5%)
Mutual labels:  pattern-matching
librxvm
non-backtracking NFA-based regular expression library, for C and Python
Stars: ✭ 57 (+42.5%)
Mutual labels:  pattern-matching
yara-rust
Rust bindings for VirusTotal/Yara
Stars: ✭ 35 (-12.5%)
Mutual labels:  pattern-matching
typy
A fragmentary bidirectional type system as a Python library
Stars: ✭ 51 (+27.5%)
Mutual labels:  pattern-matching
suitcase
Java Pattern Matching library
Stars: ✭ 21 (-47.5%)
Mutual labels:  pattern-matching
cats.match
Pattern matching for the monads in the cats Clojure library
Stars: ✭ 49 (+22.5%)
Mutual labels:  pattern-matching
Bracmat
Programming language for symbolic computation with unusual combination of pattern matching features: Tree patterns, associative patterns and expressions embedded in patterns.
Stars: ✭ 42 (+5%)
Mutual labels:  pattern-matching
siringa
Minimalist dependency injection library for Python that embraces type annotations syntax
Stars: ✭ 51 (+27.5%)
Mutual labels:  pattern-matching
Sig
The most powerful and customizable binary pattern scanner
Stars: ✭ 131 (+227.5%)
Mutual labels:  pattern-matching
dry-matcher
Flexible, expressive pattern matching for Ruby
Stars: ✭ 91 (+127.5%)
Mutual labels:  pattern-matching
conditional-expression
JavaScript functional conditional expression
Stars: ✭ 63 (+57.5%)
Mutual labels:  pattern-matching
RustLabs
The Ultimate Workshop Track for #Rust Developer
Stars: ✭ 22 (-45%)
Mutual labels:  pattern-matching
flowpython
tasty feature extensions for python3(NO MAINTENANCE!).
Stars: ✭ 66 (+65%)
Mutual labels:  pattern-matching
squire
The medieval language held together by twine.
Stars: ✭ 42 (+5%)
Mutual labels:  pattern-matching
babel-plugin-proposal-pattern-matching
the minimal grammar, high performance JavaScript pattern matching implementation
Stars: ✭ 34 (-15%)
Mutual labels:  pattern-matching
gomatch
Library created for testing JSON against patterns.
Stars: ✭ 41 (+2.5%)
Mutual labels:  pattern-matching
pattern-matching-with-typescript
TypeScript does not have any pattern matching functionality built in. This article shows several ways how you can replicate the core of a simple pattern matcher using a few simple structures and functions within TypeScript. Resulting code will have improved maintainability and better runtime type safety when done right.
Stars: ✭ 70 (+75%)
Mutual labels:  pattern-matching
mux-stream
(De)multiplex asynchronous streams
Stars: ✭ 34 (-15%)
Mutual labels:  pattern-matching

Node.js CI

Pattern Matching in Typescript

Fast and efficient pattern matching in Typescript.

pattern<[number, number]>(1, 2)
.case(1, 2)(() => {})
.case("2", 3)(() => {}) // typescript throws compile error
.match();

pattern<[number, number]>(1, 2)
.case(2, 3)(() => {})
.match(); // pattern-case throws runtime error

Examples from the test cases

test('early exit if the condition has met', () => {
  let executed = false;
  pattern<[number, number, number]>(1, 2, 3)
    .case(1, 2, 3)((a, b, c) => {return 1})
    .case(1, 2, 3)((a, b, c) => {executed = true; return 1})
    .match();
  expect(executed).toBe(false);
});

The function next could be used as a placeholder to continue with the next statement.

test('fall-through if the callback is not provided', () => {
  const result = pattern<[number, number, number]>(1, 2, 3)
    .case(1, 2, 3)(next)
    .case(1, 2, 3)((a, b, c) => {return 1})
    .match();
  expect(result).toBe(1);
});

Happy hacking!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].