UNPKG

crocks

Version:

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

27 lines (21 loc) 730 B
/** @license ISC License (c) copyright 2016 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ var curry = require('../core/curry') var isPredOrFunc = require('../core/isPredOrFunc') var isFunction = require('../core/isFunction') var predOrFunc = require('../core/predOrFunc') // unless : (a -> Boolean) | Pred -> (a -> b) -> a | b function unless(pred, f) { if(!isPredOrFunc(pred)) { throw new TypeError( 'unless: Pred or predicate function required for first argument' ) } if(!isFunction(f)) { throw new TypeError( 'unless: Function required for second argument' ) } return function (x) { return !predOrFunc(pred, x) ? f(x) : x; } } module.exports = curry(unless)