yuanchuan/match: Erlang-like pattern matching in JavaScript.

Erlang-like pattern matching in JavaScript (use at your own risk).

const { match } = require('@yuanchuan/match');

const sum = match(
  ([]) => 0,
  ([H, ...T]) => H + sum(T)

// 10
sum([1, 2, 3, 4]);


npm install --save @yuanchuan/match


Unlike the proposal-pattern-matching, patterns inside the function arguments are quite limited supported. However, it can be extended using when().

Match by number of parameters

const greeting = match(
  (User) => greeting(Str, "Hi

Read the entire article at the source link...

#codango #developer #development #coder #coding

We're happy to share this resource that we found. The content displayed on this page is property of it's original author and/or their organization.


Leave a Reply

Your email address will not be published. Required fields are marked *