Skip to content

Instantly share code, notes, and snippets.

@marcoslhc
Last active March 30, 2017 23:39
Show Gist options
  • Select an option

  • Save marcoslhc/3f6b78a50943e6afd7aa351b9b7d7d54 to your computer and use it in GitHub Desktop.

Select an option

Save marcoslhc/3f6b78a50943e6afd7aa351b9b7d7d54 to your computer and use it in GitHub Desktop.
ClassList
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()));
};
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