Created
October 30, 2016 08:13
-
-
Save amowu/5631f07536934e487d85d75aceb1a635 to your computer and use it in GitHub Desktop.
Curry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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