crocks
Version:
A collection of well known Algebraic Datatypes for your utter enjoyment.
31 lines (24 loc) • 765 B
JavaScript
/** @license ISC License (c) copyright 2016 original and current authors */
/** @author Ian Hofmann-Hicks (evil) */
var compose = require('../core/compose')
var curry = require('../core/curry')
var fl = require('../core/flNames')
var isFunction = require('../core/isFunction')
var isProfunctor = require('../core/isProfunctor')
function promap(l, r, m) {
if(!(isFunction(l) && isFunction(r))) {
throw new TypeError(
'promap: Functions required for first two arguments'
)
}
if(isFunction(m)) {
return compose(compose(r, m), l)
}
if(isProfunctor(m)) {
return (m[fl.promap] || m.promap).call(m, l, r)
}
throw new TypeError(
'promap: Function or Profunctor required for third argument'
)
}
module.exports = curry(promap)