crocks
Version:
A collection of well known Algebraic Datatypes for your utter enjoyment.
64 lines (46 loc) • 1.54 kB
JavaScript
/** @license ISC License (c) copyright 2017 original and current authors */
/** @author Ian Hofmann-Hicks (evil) */
var VERSION = 2
var _implements = require('../core/implements')
var _inspect = require('../core/inspect')
var type = require('../core/types').type('Endo')
var _type = require('../core/types').typeFn(type(), VERSION)
var fl = require('../core/flNames')
var compose = require('../core/compose')
var isFunction = require('../core/isFunction')
var isSameType = require('../core/isSameType')
var _empty =
function () { return Endo(function (x) { return x; }); }
function Endo(runWith) {
var obj;
if(!isFunction(runWith)) {
throw new TypeError('Endo: Function value required')
}
var valueOf =
function () { return runWith; }
var empty =
_empty
var inspect =
function () { return ("Endo" + (_inspect(valueOf()))); }
function concat(method) {
return function(m) {
if(!isSameType(Endo, m)) {
throw new TypeError(("Endo." + method + ": Endo required"))
}
return Endo(compose(m.valueOf(), valueOf()))
}
}
return ( obj = {
inspect: inspect, toString: inspect,
valueOf: valueOf, type: type, empty: empty, runWith: runWith,
concat: concat('concat')
}, obj[fl.empty] = empty, obj[fl.concat] = concat(fl.concat), obj['@@type'] = _type, obj.constructor = Endo, obj )
}
Endo['@@implements'] = _implements(
[ 'concat', 'empty' ]
)
Endo.empty = _empty
Endo.type = type
Endo[fl.empty] = _empty
Endo['@@type'] = _type
module.exports = Endo