Skip to content

Instantly share code, notes, and snippets.

@victorvoid

victorvoid/composability-example05.js Secret

Last active Aug 20, 2018
Embed
What would you like to do?
/* Callback :( */
const doThing = () =>
fs.readFile('codes.json', 'utf-8', (err, data) => {
if(err) throw err
const newdata = data.replace(/1/g, '2')
fs.writeFile('file2.json', newdata, (err, _) => {
if(err) throw err
console.log('success!')
}
}
/* Using future :D */
const readFile = futurize(fs.readFile)
const writeFile = futurize(fs.writefile)
const doThing = () =>
readFile('codes.json')
.map(data => data.replace('/1/g', '2')
.chain(replaced =>
writeFile('codes2.json', replaced))
doThing().fork(e => console.log(e),
r => console.log('success'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.