-
Notifications
You must be signed in to change notification settings - Fork 0
/
maybe.js
46 lines (34 loc) · 956 Bytes
/
maybe.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
function Maybe (cursor, value, msg, valid) {
if (!isMaybe(this)) return new Maybe(cursor, value, msg, valid)
this.cursor = cursor
this.value = value
this.msg = msg
this.valid = valid
}
function isMaybe(d) {
return d instanceof Maybe
}
function Just (cursor, value) {
if (!isJust(this)) return new Just(cursor, value)
Maybe.call(this, cursor, value, "ok", true)
}
Just.prototype = Object.create(Maybe.prototype, {})
Just.prototype.constructor = Just
function isJust(d) {
return d instanceof Just
}
function Nope (cursor, value, msg) {
if (!isNope(this)) return new Nope(cursor, value, msg)
Maybe.call(this, cursor, value, msg, false)
}
Nope.prototype = Object.create(Maybe.prototype, {})
Nope.prototype.constructor = Nope
function isNope(d) {
return d instanceof Nope
}
exports.Maybe = Maybe
exports.isMaybe = isMaybe
exports.Just = Just
exports.isJust = isJust
exports.Nope = Nope
exports.isNope = isNope