0.0.3 • Published 11 years ago
fantasy-async v0.0.3
fantasy-async
Wraps functions that want callbacks in pure functional promises.
example
var async = require('fantasy-async');
var get = async(request);
var write = async(fs.writeFile);
var requestPromise = get('/post/123')
.chain(function(post) { return get('/user/'+post.author); })
.fold(
function error() { return Result.notFound() },
function done(user) { return Result.ok(JSON.stringify(user)) }
);
install
npm install fantasy-async
api
async :: (a → (e → r → ()) → ()) → a → EitherT Promise e r
Given a function that takes a Node-style function (err, result)
callback, returns a function that takes the same arguments and returns an EitherT Promise
wrapping the error as Left
or the result as Right
.
See the code for EitherT for the complete API.