Skip to content

Instantly share code, notes, and snippets.

@FGRibreau
Created December 29, 2015 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FGRibreau/7864788523bb0a5cdfc5 to your computer and use it in GitHub Desktop.
Save FGRibreau/7864788523bb0a5cdfc5 to your computer and use it in GitHub Desktop.
match-when - Pattern matching for modern JavaScript - https://github.com/FGRibreau/match-when
function length(list){
return match({
[when([])]: 0,
[when()]: ([head, ...tail]) => 1 + length(tail)
})(list);
}
length([1, 1, 1]); // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment