UNPKG

crocks

Version:

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

32 lines (24 loc) 863 B
/** @license ISC License (c) copyright 2016 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ var array = require('../core/array') var curry = require('../core/curry') var isApply = require('../core/isApply') var isArray = require('../core/isArray') var isFunction = require('../core/isFunction') var isSameType = require('../core/isSameType') var map = array.map var ap = array.ap // liftA2 :: Applicative m => (a -> b -> c) -> m a -> m b -> m c function liftA2(fn, x, y) { if(!isFunction(fn)) { throw new TypeError('liftA2: Function required for first argument') } if(!((isApply(x) || isArray(x)) && isSameType(x, y))) { throw new TypeError('liftA2: Applys of same type required for last two arguments') } if(isArray(x)) { return ap(y, map(fn, x)) } return x.map(fn).ap(y) } module.exports = curry(liftA2)