fantasy-async

Wrap Node.js callback functions in functional promises


Keywords
fantasy-land, async, promises, callbacks
License
MIT
Install
npm install fantasy-async@0.0.3

Documentation

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.

licence

MIT