-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperation.mjs
More file actions
126 lines (107 loc) · 1.89 KB
/
operation.mjs
File metadata and controls
126 lines (107 loc) · 1.89 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* Pipes value
* @param {any} v
* @returns {any} the same value in input
*/
export function pipe(v){
return v
}
/**
* do nothing
*/
export function noop(){}
/**
* returns true
*/
export function yes(){
return true
}
/**
* returns false
*/
export function no(){
return false
}
/**
* apply a function to arguments
* @param {function} f
* @param {...any} args
*/
export function apply(f, ...args) {
return f.apply(this, args)
}
/**
* return a function that apply a handler to arguments
* @param {function} f
* @param {...any} values
*/
export function applyWithConst(f, ...values){
return (obj) => f(obj, ...values)
}
/**
* performs a strict equal comparison
* @param {any} obj
* @param {any} value
*/
export function equals(obj, value){
return obj === value
}
/**
* performs a strict different comparison
* @param {any} obj
* @param {any} value
*/
export function different(obj, value){
return obj !== value
}
/**
* return a value provider function
* @param val value to be returned
*/
export function constant(val) {
return apply.bind(void 0, pipe, val)
}
/**
* generator for comparison functions with constant values
* @function
* @param {any} value
* @param {any} costant
*/
export const compareWhitConst = applyWithConst.bind(void 0, equals)
/**
* @function
* @param {any} value
*/
export const isNull = compareWhitConst(null)
/**
* @function
* @param {any} value
*/
export const isUndefined = compareWhitConst(void 0)
/**
* @function
* @param {any} value
*/
export const isTrue = compareWhitConst(true)
/**
* @function
* @param {any} value
*/
export const isFalse = compareWhitConst(false)
export function or(a, b){
return a || b
}
export function and(a, b){
return a && b
}
export function not(a){
return !a
}
export function sum(a, b){
return a + b
}
export function inverse(f) {
return function(...args) {
return f.apply(this, args.reverse())
}
}