Created
July 21, 2017 17:22
-
-
Save awei01/9319094cbad3c07d0ff65dc356d13cb5 to your computer and use it in GitHub Desktop.
This file contains 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 _getInvalidRule (rules, data, value) { | |
const resolveRuleResult = partial(_resolveRuleResult, [rules, data, value]) | |
const reducer = partial(_reducer, [resolveRuleResult]) | |
return Object.keys(rules).reduce(reducer, Promise.resolve(null)) | |
} | |
function _reducer (callback, accumulator, key) { | |
return pipeP( | |
always(accumulator), | |
ifElse(identity, always(accumulator), partial(callback, [accumulator, key])) | |
)() // why do I end up having to put parens here to invoke the funciton? | |
} | |
function _resolveRuleResult (rules, data, value, accumulator, key) { | |
return pipeP( | |
always(Promise.resolve()), | |
partial(checkRule, [rules[key], data, value]), | |
ifElse(identity, always(accumulator), always(key)) | |
)() // why do I end up having to put parens here to invoke the funciton? | |
} | |
function checkRule (rule, data, value) { | |
return rule(value, data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment