UNPKG

crocks

Version:

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

24 lines (18 loc) 649 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 isApplicative = require('../core/isApplicative') var isArray = require('../core/isArray') var isSameType = require('../core/isSameType') // ap :: Applicative m => m a -> m (a -> b) -> m b function ap(m, x) { if(!((isApplicative(m) || isArray(m)) && isSameType(m, x))) { throw new TypeError('ap: Both arguments must be Applys of the same type') } if(isArray(x)) { return array.ap(m, x) } return x.ap(m) } module.exports = curry(ap)