crocks
Version:
A collection of well known Algebraic Datatypes for your utter enjoyment.
26 lines (20 loc) • 800 B
JavaScript
/** @license ISC License (c) copyright 2017 original and current authors */
/** @author Ian Hofmann-Hicks (evil) */
var compose = require('../core/compose')
var curry = require('../core/curry')
var isPredOrFunc = require('../core/isPredOrFunc')
var isFunction = require('../core/isFunction')
var safe = require('./safe')
var map =
function (fn) { return function (m) { return m.map(fn); }; }
// safeLift : ((a -> Boolean) | Pred) -> (a -> b) -> a -> Maybe b
function safeLift(pred, fn) {
if(!isPredOrFunc(pred)) {
throw new TypeError('safeLift: Pred or predicate function required for first argument')
}
else if(!isFunction(fn)) {
throw new TypeError('safeLift: Function required for second argument')
}
return compose(map(fn), safe(pred))
}
module.exports = curry(safeLift)