Last active
April 8, 2017 04:15
-
-
Save marcoslhc/df57757e216705938dc08920a0fbed47 to your computer and use it in GitHub Desktop.
filter -> map -> reduce
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
| function filterReduce(predicate) { | |
| return function (accum, value) { | |
| if (predicate(value)) { | |
| return accum.concat(value); | |
| } else { | |
| return accum; | |
| } | |
| }; | |
| }; | |
| function mapReduce(morphism) { | |
| return function (accum, value) { | |
| return accum.concat(morphism(value)); | |
| } | |
| } | |
| ClassList.of([ | |
| 'btn__background--solarized', | |
| 'btn__text--solarized', | |
| 'btn__overlay--solarized', | |
| 'btn__icon', | |
| 'btn__placeholder' | |
| ]).reduce(filterReduce(str => /--solarized/.test(str))) | |
| .reduce(mapReduce(str => str.concat('--active'))); | |
| // ClassList.of([ | |
| // "btn__background--solarized--active", | |
| // "btn__text--solarized--active", | |
| // "btn__overlay--solarized--active" | |
| // ]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment