Skip to content

Instantly share code, notes, and snippets.

@awei01
Created July 21, 2017 17:22
Show Gist options
  • Save awei01/9319094cbad3c07d0ff65dc356d13cb5 to your computer and use it in GitHub Desktop.
Save awei01/9319094cbad3c07d0ff65dc356d13cb5 to your computer and use it in GitHub Desktop.
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