fantasy-async

0.0.3 • Public • Published

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

/fantasy-async/

    Package Sidebar

    Install

    npm i fantasy-async

    Weekly Downloads

    2

    Version

    0.0.3

    License

    MIT

    Last publish

    Collaborators

    • quarterto