FunctionSelect: Select a function that passes a condition. A functional alternative to switch-case.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

16 lines
295 B

'use strict';
const Select = (value, resolve) => ({
value,
for: (test, fn) => {
if (resolve) return {
...Select(value, resolve),
resolve
};
if (test) return Select(value, fn);
return Select(value);
},
resolve: resolve ? resolve : () => undefined
});
module.exports = Select;