crocks
Version:
A collection of well known Algebraic Datatypes for your utter enjoyment.
69 lines (50 loc) • 1.71 kB
JavaScript
/** @license ISC License (c) copyright 2016 original and current authors */
/** @author Ian Hofmann-Hicks (evil) */
var VERSION = 2
var _implements = require('../core/implements')
var _inspect = require('../core/inspect')
var _equals = require('../core/equals')
var type = require('../core/types').type('All')
var _type = require('../core/types').typeFn(type(), VERSION)
var fl = require('../core/flNames')
var isFunction = require('../core/isFunction')
var isNil = require('../core/isNil')
var isSameType = require('../core/isSameType')
var _empty =
function () { return All(true); }
function All(b) {
var obj;
var x = isNil(b) ? _empty().valueOf() : b
if(!arguments.length || isFunction(x)) {
throw new TypeError('All: Non-function value required')
}
var valueOf =
function () { return !!x; }
var empty =
_empty
var equals =
function (m) { return isSameType(All, m)
&& _equals(x, m.valueOf()); }
var inspect =
function () { return ("All" + (_inspect(valueOf()))); }
function concat(method) {
return function(m) {
if(!isSameType(All, m)) {
throw new TypeError(("All." + method + ": All required"))
}
return All(m.valueOf() && valueOf())
}
}
return ( obj = {
inspect: inspect, toString: inspect,
equals: equals, valueOf: valueOf, type: type, empty: empty
}, obj['@@type'] = _type, obj.concat = concat('concat'), obj[fl.equals] = equals, obj[fl.concat] = concat(fl.concat), obj[fl.empty] = empty, obj.constructor = All, obj )
}
All['@@implements'] = _implements(
[ 'equals', 'concat', 'empty' ]
)
All.empty = _empty
All.type = type
All[fl.empty] = _empty
All['@@type'] = _type
module.exports = All