UNPKG

crocks

Version:

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

36 lines (26 loc) 975 B
/** @license ISC License (c) copyright 2017 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ var Last = require('.') var Either = require('../core/types').proxy('Either') var curry = require('../core/curry') var isFunction = require('../core/isFunction') var isSameType = require('../core/isSameType') var applyTransform = function (either) { return either.either(Last.empty, Last); } // eitherToLast : Either b a -> Last a // eitherToLast : (a -> Either c b) -> a -> Last b function eitherToLast(either) { if(isFunction(either)) { return function(x) { var m = either(x) if(!isSameType(Either, m)) { throw new TypeError('eitherToLast: Either returning function required') } return applyTransform(m) } } if(isSameType(Either, either)) { return applyTransform(either) } throw new TypeError('eitherToLast: Either or Either returning function required') } module.exports = curry(eitherToLast)