UNPKG

crocks

Version:

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

30 lines (21 loc) 671 B
/** @license ISC License (c) copyright 2016 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ var Pair = require('../core/types').proxy('Pair') var isFunction = require('../core/isFunction') var isSameType = require('../core/isSameType') var identity = function (x) { return x; } function first(m) { if(isFunction(m)) { return function(x) { if(!isSameType(Pair, x)) { throw new TypeError('first: Pair required as input') } return x.bimap(m, identity) } } if(m && isFunction(m.first)) { return m.first() } throw new TypeError('first: Arrow, Function or Star required') } module.exports = first