crocks
Version:
A collection of well known Algebraic Datatypes for your utter enjoyment.
28 lines (20 loc) • 621 B
JavaScript
/** @license ISC License (c) copyright 2017 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')
function both(m) {
if(isFunction(m)) {
return function(x) {
if(!isSameType(Pair, x)) {
throw new TypeError('both: Pair required as input')
}
return x.bimap(m, m)
}
}
if(m && isFunction(m.both)) {
return m.both()
}
throw new TypeError('both: Strong Function or Profunctor required')
}
module.exports = both