Last Updated: February 25, 2016
· dscape

Define your own recursion in JavaScript with Pattern Matching and Functional Programming

pattern is a way to do pattern matching in javascript that helps you with asynchronous iterations


map(_, [], ac, cb, 
  function map_done(f, l, ac, cb) { return cb(ac); });

map(f, l, ac, cb, 
  function map_catch_all(f, l, ac, cb) {
    ac.push(f(l.shift())); // head
    map(f, l, ac, cb); // l is now tail

If you understand this, you will like pattern!