-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Sum.js
57 lines (43 loc) · 1.42 KB
/
Sum.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
47
48
49
50
51
52
53
54
55
56
57
(f => {
'use strict';
if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = f (require ('sanctuary-def'),
require ('sanctuary-show'),
require ('sanctuary-type-classes'),
require ('sanctuary-type-identifiers'));
} else {
self.Sum = f (self.sanctuaryDef,
self.sanctuaryShow,
self.sanctuaryTypeClasses,
self.sanctuaryTypeIdentifiers);
}
}) (($, show, Z, type) => {
'use strict';
// Sum :: Number -> Sum
function Sum(value) {
if (!(this instanceof Sum)) return new Sum (value);
this.value = value;
}
// sumTypeIdent :: String
const sumTypeIdent = Sum.prototype['@@type'] = 'sanctuary-site/Sum';
Sum['fantasy-land/empty'] = () => Sum (0);
Sum.prototype['fantasy-land/equals'] = function(other) {
return Z.equals (this.value, other.value);
};
Sum.prototype['fantasy-land/concat'] = function(other) {
return Sum (this.value + other.value);
};
Sum.prototype['fantasy-land/invert'] = function() {
return Sum (-this.value);
};
Sum.prototype['@@show'] = function() {
return 'Sum (' + show (this.value) + ')';
};
// Sum.Type :: Type
Sum.Type = $.NullaryType
('Sum')
('https://github.com/sanctuary-js/sanctuary-site/blob/gh-pages/adt/Sum.js')
([])
(x => type (x) === sumTypeIdent);
return Sum;
});