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