Skip to content

Instantly share code, notes, and snippets.

@amowu
Created October 30, 2016 08:13
Show Gist options
  • Select an option

  • Save amowu/5631f07536934e487d85d75aceb1a635 to your computer and use it in GitHub Desktop.

Select an option

Save amowu/5631f07536934e487d85d75aceb1a635 to your computer and use it in GitHub Desktop.
Curry
var curry = _.curry;
var match = curry((what, str) => str.match(what));
var replace = curry((what, replacement, str) => str.replace(what, replacement));
var filter = curry((f, ary) => ary.filter(f));
var map = curry((f, ary) => ary.map(f));
match(/\s+/g, 'hello world');
// [" "]
match(/\s+/g)('hello world');
// [" "]
var hasSpaces = match(/\s+/g);
hasSpaces('hello world');
// [" "]
hasSpaces('spaceless');
// null
filter(hasSpaces, ['spaceless', 'hello world']);
// ["hello world"]
var findSpaces = filter(hasSpaces);
findSpaces(['spaceless', 'hello world']);
// ["hello world"]
var noVowels = replace(/[aeoiu]/ig);
var censored = noVowels('*');
censored('hello world')
// "h*ll* w*rld"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment