plastikaweb
11/29/2016 - 9:20 AM

javascript currying examples using lodash dependency (_.curry method)

javascript currying examples using lodash dependency (_.curry method)

var match = _.curry(function(what, str) {
  return str.match(what);
});

var replace = _.curry(function(what, replacement, str) {
  return str.replace(what, replacement);
});

var filter = _.curry(function(f, ary) {
  return ary.filter(f);
});

var map = _.curry(function(f, ary) {
  return ary.map(f);
}); 

console.log(
  match(/\s+/g)("hello world")
);

console.log(
  replace(/[aeiou]/ig)("#")('La vida es bella')
);

console.log(
  filter(function (d) {
    return d > 2;
  })
  ([0,1,2,3,4,5])
);

console.log(
  map(function (d) {
    return d*2;
  })
  ([0,1,2,3,4,5])
);