Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const config = {
init: 1,
condition: x => x <= 256,
each: x => console.info(`INFO: ${x}`),
afterEach: x => x * 2,
};
// DO NOT EDIT BELOW THIS LINE
(() => {
const defaults = {
init: 0,
condition: x => x < 12,
each: console.log,
afterEach: x => x + 1,
};
const getValueFactory = (defaultObject, configObject) => {
if (!defaultObject) {
throw new Error('Missing default object');
} else {
return prop => {
if (configObject && configObject.hasOwnProperty(prop)) {
return configObject[prop];
} else if (defaultObject.hasOwnProperty(prop)) {
return defaultObject[prop];
} else {
throw new Error(`Missing prop: ${prop}`);
}
};
}
};
const getValue = getValueFactory(defaults, config);
for (
let state = getValue('init');
getValue('condition')(state);
state = getValue('afterEach')(state)
) {
getValue('each')(state);
}
})(config);
@christianbundy
Copy link
Author

christianbundy commented Mar 20, 2018

please nobody ever use this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment