Created
March 20, 2018 17:44
-
-
Save christianbundy/9a2aa0b4cceb967cf565527a03e86c70 to your computer and use it in GitHub Desktop.
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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
please nobody ever use this