Last active
March 30, 2017 23:39
-
-
Save marcoslhc/3f6b78a50943e6afd7aa351b9b7d7d54 to your computer and use it in GitHub Desktop.
ClassList
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 ClassList(unwrapFn) { | |
| this.getClasses = unwrapFn; | |
| return this; | |
| } | |
| // Let's make it a "pointed functor" | |
| ClassList.of = function(classes) { | |
| return new ClassList(() => { | |
| return classes; | |
| }); | |
| }; | |
| // And is a Functor after all. It should map | |
| ClassList.prototype.map = function(fn) { | |
| return ClassList.of(fn(this.getClasses())); | |
| }; |
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
| const mapFn = fn => lst => lst.map(fn); | |
| const solarize = cls => cls.concat('--solarized'); | |
| const mapSolarize = mapFn(solarize); | |
| ClassList.of([ | |
| 'btn', | |
| 'btn-primary', | |
| 'btn-primary--active' | |
| ]).map(mapSolarize).getClasses(); | |
| // ['btn--solarized','btn-primary--solarized', 'btn-primary--active--solarized'] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment