UNPKG

crocks

Version:

A collection of well known Algebraic Datatypes for your utter enjoyment.

27 lines (20 loc) 729 B
/** @license ISC License (c) copyright 2018 original and current authors */ /** @author Dale Francis */ var curry = require('../core/curry') var isSameType = require('../core/isSameType') var isFunction = require('../core/isFunction') var Async = require('../core/types').proxy('Async') var toPromise = function (m) { if(!isSameType(Async, m)) { throw new TypeError('asyncToPromise: Async or a function returning an Async required') } return m.toPromise() } // asyncToPromise :: m e a -> Promise a e // asyncToPromise :: (a -> m e b) -> a -> Promise b e function asyncToPromise(m) { return isFunction(m) ? function (x) { return toPromise(m(x)); } : toPromise(m) } module.exports = curry(asyncToPromise)