UNPKG

crocks

Version:

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

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