Created
March 11, 2018 19:29
-
-
Save cmstead/2b893b866aef82e8888d7878be7bdc5d to your computer and use it in GitHub Desktop.
A simple, generic set combinator, because reasons.
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 () { | |
'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