Skip to content

Instantly share code, notes, and snippets.

@christianbundy
Created March 20, 2018 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianbundy/9a2aa0b4cceb967cf565527a03e86c70 to your computer and use it in GitHub Desktop.
Save christianbundy/9a2aa0b4cceb967cf565527a03e86c70 to your computer and use it in GitHub Desktop.
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

please nobody ever use this

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