Created
December 1, 2016 17:58
-
-
Save parweb/e69bf1f6dcebdd445f174ecd426f5534 to your computer and use it in GitHub Desktop.
test-railway.js
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
const addOne = value => { | |
return value + 1; | |
}; | |
const failIfOdd = value => { | |
return value + 1; | |
}; | |
function railway ( chain ) { | |
return new Promise((resolve) => { | |
chain( val => new Promise( resolve => resolve( val ) ) ) | |
.then( result => resolve( [ true, result ] ) ) | |
.catch( error => resolve( [ false, error ] ) ); | |
}); | |
} | |
const [ ok, result ] = railway( | |
start => { | |
start( 1 ) | |
.then( addOne ) | |
.then( failIfOdd ) | |
.then( addOne ) | |
} | |
); | |
console.log(ok, result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment