forked from kriskowal/gtor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operators.js
49 lines (33 loc) · 1.03 KB
/
operators.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
// The operators module provides named function objects corresponding to
// language operators.
"use strict";
// The equals and compare operators provided by the Collections package allow
// deep comparison of arbitrary values and delegate to the eponymous methods of
// instances if they are defined.
require("collections/shim-object");
exports.equals = Object.equals;
exports.compare = Object.compare;
exports.not = function (x) { return !x };
exports.and = function (x, y) { return x && y };
exports.or = function (x, y) { return x || y };
exports.add = function (x, y) {
return x + y;
};
exports.sub = function (x, y) {
return x - y;
};
exports.div = function (x, y) {
return x / y;
};
exports.mul = function (x, y) {
return x * y;
};
exports.tuple = function () {
return Array.prototype.slice.call(arguments);
};
// Behaviors and signals will propagate undefined if any operand is not
// defined.
exports.defined = function (value) {
// !NaN && !null && !undefined
return value === value && value != null;
};