Skip to content

Instantly share code, notes, and snippets.

@cmstead
Created March 11, 2018 19:29
Show Gist options
  • Save cmstead/2b893b866aef82e8888d7878be7bdc5d to your computer and use it in GitHub Desktop.
Save cmstead/2b893b866aef82e8888d7878be7bdc5d to your computer and use it in GitHub Desktop.
A simple, generic set combinator, because reasons.
(function () {
'use strict';
const buildCombination =
(currentList, values) =>
values.map((value) => currentList.concat([value]));
const buildPartialCombination =
(newSet) =>
(setCombination, value) =>
setCombination.concat(buildCombination(value, newSet));
const combineSets =
(currentSet, newSet) =>
currentSet.reduce(buildPartialCombination(newSet), []);
const combineValues =
(...args) =>
args.reduce(combineSets, [[]]);
const setCombinator = {
combineValues: combineValues
};
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = setCombinator;
} else {
window.setCombinator = setCombinator;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment