-
Notifications
You must be signed in to change notification settings - Fork 58
/
nothing.js
46 lines (33 loc) · 787 Bytes
/
nothing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"use strict";
var { isFunction, } = require("./lib/util.js");
var brand = {};
module.exports = Object.assign(Nothing,{
of: Nothing, pure: Nothing, unit: Nothing,
is, isEmpty,
});
// **************************
function Nothing() {
var publicAPI = {
map: noop, chain: noop, flatMap: noop, bind: noop,
ap: noop, concat: noop, _inspect, _is,
[Symbol.toStringTag]: "Nothing",
};
return publicAPI;
// *********************
function noop() {
return publicAPI;
}
function _inspect() {
return `${publicAPI[Symbol.toStringTag]}()`;
}
function _is(br) {
return br === brand;
}
}
function is(val) {
return val && isFunction(val._is) && val._is(brand);
}
// default isEmpty(), can be overidden
function isEmpty(val) {
return val == null; // null or undefined
}