Created
August 30, 2016 13:30
-
-
Save bultas/21c48ea84e5d1a1f7d3ba3a2b2c15948 to your computer and use it in GitHub Desktop.
Dispatch - traverse functions as long as any function return something else then undefined
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
import {isNil} from 'ramda'; | |
export function dispatch(...funcs) { | |
return function(...args) { | |
for (let fun of funcs) { | |
let ret = fun(...args); | |
if (!isNil(ret)) return ret; | |
} | |
return undefined; | |
}; | |
} | |
// USAGE | |
dispatch( | |
dispatchAuthStarted, | |
dispatchAuthCompleted, | |
dispatchAuthFailed, | |
defaultAction | |
)('value'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment