rambda 7.3.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +387 -2308
- package/dist/rambda.js +50 -399
- package/dist/rambda.umd.js +1 -1
- package/immutable.d.ts +296 -240
- package/index.d.ts +296 -240
- package/package.json +21 -33
- package/rambda.js +188 -0
- package/src/dropLastWhile.js +9 -8
- package/src/dropWhile.js +12 -10
- package/src/equals.js +0 -12
- package/src/map.js +1 -0
- package/src/nop.js +1 -0
- package/src/takeLastWhile.js +6 -7
- package/src/takeWhile.js +9 -10
- package/src/test.js +1 -1
- package/src/uniqBy.js +4 -7
- package/src/unnest.js +9 -0
- package/dist/rambda.mjs +0 -2549
package/dist/rambda.mjs
DELETED
|
@@ -1,2549 +0,0 @@
|
|
|
1
|
-
function F() {
|
|
2
|
-
return false;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function T() {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function add(a, b) {
|
|
10
|
-
if (arguments.length === 1) return _b => add(a, _b);
|
|
11
|
-
return Number(a) + Number(b);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const cloneList = list => Array.prototype.slice.call(list);
|
|
15
|
-
|
|
16
|
-
function curry(fn, args = []) {
|
|
17
|
-
return (..._args) => (rest => rest.length >= fn.length ? fn(...rest) : curry(fn, rest))([...args, ..._args]);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function adjustFn(index, replaceFn, list) {
|
|
21
|
-
const actualIndex = index < 0 ? list.length + index : index;
|
|
22
|
-
if (index >= list.length || actualIndex < 0) return list;
|
|
23
|
-
const clone = cloneList(list);
|
|
24
|
-
clone[actualIndex] = replaceFn(clone[actualIndex]);
|
|
25
|
-
return clone;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const adjust = curry(adjustFn);
|
|
29
|
-
|
|
30
|
-
function all(predicate, list) {
|
|
31
|
-
if (arguments.length === 1) return _list => all(predicate, _list);
|
|
32
|
-
|
|
33
|
-
for (let i = 0; i < list.length; i++) {
|
|
34
|
-
if (!predicate(list[i])) return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function allPass(predicates) {
|
|
41
|
-
return (...input) => {
|
|
42
|
-
let counter = 0;
|
|
43
|
-
|
|
44
|
-
while (counter < predicates.length) {
|
|
45
|
-
if (!predicates[counter](...input)) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
counter++;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return true;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function always(x) {
|
|
57
|
-
return _ => x;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function and(a, b) {
|
|
61
|
-
if (arguments.length === 1) return _b => and(a, _b);
|
|
62
|
-
return a && b;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function any(predicate, list) {
|
|
66
|
-
if (arguments.length === 1) return _list => any(predicate, _list);
|
|
67
|
-
let counter = 0;
|
|
68
|
-
|
|
69
|
-
while (counter < list.length) {
|
|
70
|
-
if (predicate(list[counter], counter)) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
counter++;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function anyPass(predicates) {
|
|
81
|
-
return (...input) => {
|
|
82
|
-
let counter = 0;
|
|
83
|
-
|
|
84
|
-
while (counter < predicates.length) {
|
|
85
|
-
if (predicates[counter](...input)) {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
counter++;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return false;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function append(x, input) {
|
|
97
|
-
if (arguments.length === 1) return _input => append(x, _input);
|
|
98
|
-
if (typeof input === 'string') return input.split('').concat(x);
|
|
99
|
-
const clone = cloneList(input);
|
|
100
|
-
clone.push(x);
|
|
101
|
-
return clone;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function apply(fn, args) {
|
|
105
|
-
if (arguments.length === 1) {
|
|
106
|
-
return _args => apply(fn, _args);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return fn.apply(this, args);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const {
|
|
113
|
-
isArray
|
|
114
|
-
} = Array;
|
|
115
|
-
|
|
116
|
-
function __findHighestArity(spec, max = 0) {
|
|
117
|
-
for (const key in spec) {
|
|
118
|
-
if (spec.hasOwnProperty(key) === false || key === 'constructor') continue;
|
|
119
|
-
|
|
120
|
-
if (typeof spec[key] === 'object') {
|
|
121
|
-
max = Math.max(max, __findHighestArity(spec[key]));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (typeof spec[key] === 'function') {
|
|
125
|
-
max = Math.max(max, spec[key].length);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return max;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function __filterUndefined() {
|
|
133
|
-
const defined = [];
|
|
134
|
-
let i = 0;
|
|
135
|
-
const l = arguments.length;
|
|
136
|
-
|
|
137
|
-
while (i < l) {
|
|
138
|
-
if (typeof arguments[i] === 'undefined') break;
|
|
139
|
-
defined[i] = arguments[i];
|
|
140
|
-
i++;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return defined;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function __applySpecWithArity(spec, arity, cache) {
|
|
147
|
-
const remaining = arity - cache.length;
|
|
148
|
-
if (remaining === 1) return x => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x));
|
|
149
|
-
if (remaining === 2) return (x, y) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y));
|
|
150
|
-
if (remaining === 3) return (x, y, z) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y, z));
|
|
151
|
-
if (remaining === 4) return (x, y, z, a) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y, z, a));
|
|
152
|
-
if (remaining > 4) return (...args) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, ...args));
|
|
153
|
-
|
|
154
|
-
if (isArray(spec)) {
|
|
155
|
-
const ret = [];
|
|
156
|
-
let i = 0;
|
|
157
|
-
const l = spec.length;
|
|
158
|
-
|
|
159
|
-
for (; i < l; i++) {
|
|
160
|
-
if (typeof spec[i] === 'object' || isArray(spec[i])) {
|
|
161
|
-
ret[i] = __applySpecWithArity(spec[i], arity, cache);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (typeof spec[i] === 'function') {
|
|
165
|
-
ret[i] = spec[i](...cache);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return ret;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const ret = {};
|
|
173
|
-
|
|
174
|
-
for (const key in spec) {
|
|
175
|
-
if (spec.hasOwnProperty(key) === false || key === 'constructor') continue;
|
|
176
|
-
|
|
177
|
-
if (typeof spec[key] === 'object') {
|
|
178
|
-
ret[key] = __applySpecWithArity(spec[key], arity, cache);
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (typeof spec[key] === 'function') {
|
|
183
|
-
ret[key] = spec[key](...cache);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return ret;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function applySpec(spec, ...args) {
|
|
191
|
-
const arity = __findHighestArity(spec);
|
|
192
|
-
|
|
193
|
-
if (arity === 0) {
|
|
194
|
-
return () => ({});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const toReturn = __applySpecWithArity(spec, arity, args);
|
|
198
|
-
|
|
199
|
-
return toReturn;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function assocFn(prop, newValue, obj) {
|
|
203
|
-
return Object.assign({}, obj, {
|
|
204
|
-
[prop]: newValue
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const assoc = curry(assocFn);
|
|
209
|
-
|
|
210
|
-
function _isInteger(n) {
|
|
211
|
-
return n << 0 === n;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const isInteger = Number.isInteger || _isInteger;
|
|
215
|
-
|
|
216
|
-
function assocPathFn(path, newValue, input) {
|
|
217
|
-
const pathArrValue = typeof path === 'string' ? path.split('.').map(x => isInteger(Number(x)) ? Number(x) : x) : path;
|
|
218
|
-
|
|
219
|
-
if (pathArrValue.length === 0) {
|
|
220
|
-
return newValue;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const index = pathArrValue[0];
|
|
224
|
-
|
|
225
|
-
if (pathArrValue.length > 1) {
|
|
226
|
-
const condition = typeof input !== 'object' || input === null || !input.hasOwnProperty(index);
|
|
227
|
-
const nextInput = condition ? isInteger(pathArrValue[1]) ? [] : {} : input[index];
|
|
228
|
-
newValue = assocPathFn(Array.prototype.slice.call(pathArrValue, 1), newValue, nextInput);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (isInteger(index) && isArray(input)) {
|
|
232
|
-
const arr = cloneList(input);
|
|
233
|
-
arr[index] = newValue;
|
|
234
|
-
return arr;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return assoc(index, newValue, input);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const assocPath = curry(assocPathFn);
|
|
241
|
-
|
|
242
|
-
function _curryN(n, cache, fn) {
|
|
243
|
-
return function () {
|
|
244
|
-
let ci = 0;
|
|
245
|
-
let ai = 0;
|
|
246
|
-
const cl = cache.length;
|
|
247
|
-
const al = arguments.length;
|
|
248
|
-
const args = new Array(cl + al);
|
|
249
|
-
|
|
250
|
-
while (ci < cl) {
|
|
251
|
-
args[ci] = cache[ci];
|
|
252
|
-
ci++;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
while (ai < al) {
|
|
256
|
-
args[cl + ai] = arguments[ai];
|
|
257
|
-
ai++;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const remaining = n - args.length;
|
|
261
|
-
return args.length >= n ? fn.apply(this, args) : _arity$1(remaining, _curryN(n, args, fn));
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function _arity$1(n, fn) {
|
|
266
|
-
switch (n) {
|
|
267
|
-
case 0:
|
|
268
|
-
return function () {
|
|
269
|
-
return fn.apply(this, arguments);
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
case 1:
|
|
273
|
-
return function (_1) {
|
|
274
|
-
return fn.apply(this, arguments);
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
case 2:
|
|
278
|
-
return function (_1, _2) {
|
|
279
|
-
return fn.apply(this, arguments);
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
case 3:
|
|
283
|
-
return function (_1, _2, _3) {
|
|
284
|
-
return fn.apply(this, arguments);
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
case 4:
|
|
288
|
-
return function (_1, _2, _3, _4) {
|
|
289
|
-
return fn.apply(this, arguments);
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
case 5:
|
|
293
|
-
return function (_1, _2, _3, _4, _5) {
|
|
294
|
-
return fn.apply(this, arguments);
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
case 6:
|
|
298
|
-
return function (_1, _2, _3, _4, _5, _6) {
|
|
299
|
-
return fn.apply(this, arguments);
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
case 7:
|
|
303
|
-
return function (_1, _2, _3, _4, _5, _6, _7) {
|
|
304
|
-
return fn.apply(this, arguments);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
case 8:
|
|
308
|
-
return function (_1, _2, _3, _4, _5, _6, _7, _8) {
|
|
309
|
-
return fn.apply(this, arguments);
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
case 9:
|
|
313
|
-
return function (_1, _2, _3, _4, _5, _6, _7, _8, _9) {
|
|
314
|
-
return fn.apply(this, arguments);
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
default:
|
|
318
|
-
return function (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) {
|
|
319
|
-
return fn.apply(this, arguments);
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function curryN(n, fn) {
|
|
325
|
-
if (arguments.length === 1) return _fn => curryN(n, _fn);
|
|
326
|
-
|
|
327
|
-
if (n > 10) {
|
|
328
|
-
throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return _arity$1(n, _curryN(n, [], fn));
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function bind(fn, thisObj) {
|
|
335
|
-
if (arguments.length === 1) {
|
|
336
|
-
return _thisObj => bind(fn, _thisObj);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
return curryN(fn.length, (...args) => fn.apply(thisObj, args));
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function both(f, g) {
|
|
343
|
-
if (arguments.length === 1) return _g => both(f, _g);
|
|
344
|
-
return (...input) => f(...input) && g(...input);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function chain(fn, list) {
|
|
348
|
-
if (arguments.length === 1) {
|
|
349
|
-
return _list => chain(fn, _list);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return [].concat(...list.map(fn));
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
function clampFn(min, max, input) {
|
|
356
|
-
if (min > max) {
|
|
357
|
-
throw new Error('min must not be greater than max in clamp(min, max, value)');
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (input >= min && input <= max) return input;
|
|
361
|
-
if (input > max) return max;
|
|
362
|
-
if (input < min) return min;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
const clamp = curry(clampFn);
|
|
366
|
-
|
|
367
|
-
function clone(input) {
|
|
368
|
-
const out = isArray(input) ? Array(input.length) : {};
|
|
369
|
-
if (input && input.getTime) return new Date(input.getTime());
|
|
370
|
-
|
|
371
|
-
for (const key in input) {
|
|
372
|
-
const v = input[key];
|
|
373
|
-
out[key] = typeof v === 'object' && v !== null ? v.getTime ? new Date(v.getTime()) : clone(v) : v;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
return out;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function complement(fn) {
|
|
380
|
-
return (...input) => !fn(...input);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
class ReduceStopper {
|
|
384
|
-
constructor(value) {
|
|
385
|
-
this.value = value;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
function reduceFn(reducer, acc, list) {
|
|
391
|
-
if (!isArray(list)) {
|
|
392
|
-
throw new TypeError('reduce: list must be array or iterable');
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
let index = 0;
|
|
396
|
-
const len = list.length;
|
|
397
|
-
|
|
398
|
-
while (index < len) {
|
|
399
|
-
acc = reducer(acc, list[index], index, list);
|
|
400
|
-
|
|
401
|
-
if (acc instanceof ReduceStopper) {
|
|
402
|
-
return acc.value;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
index++;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
return acc;
|
|
409
|
-
}
|
|
410
|
-
const reduce = curry(reduceFn);
|
|
411
|
-
const reduceStopper = value => new ReduceStopper(value);
|
|
412
|
-
|
|
413
|
-
function _arity(n, fn) {
|
|
414
|
-
switch (n) {
|
|
415
|
-
case 0:
|
|
416
|
-
return function () {
|
|
417
|
-
return fn.apply(this, arguments);
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
case 1:
|
|
421
|
-
return function (a0) {
|
|
422
|
-
return fn.apply(this, arguments);
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
case 2:
|
|
426
|
-
return function (a0, a1) {
|
|
427
|
-
return fn.apply(this, arguments);
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
case 3:
|
|
431
|
-
return function (a0, a1, a2) {
|
|
432
|
-
return fn.apply(this, arguments);
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
case 4:
|
|
436
|
-
return function (a0, a1, a2, a3) {
|
|
437
|
-
return fn.apply(this, arguments);
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
case 5:
|
|
441
|
-
return function (a0, a1, a2, a3, a4) {
|
|
442
|
-
return fn.apply(this, arguments);
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
case 6:
|
|
446
|
-
return function (a0, a1, a2, a3, a4, a5) {
|
|
447
|
-
return fn.apply(this, arguments);
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
case 7:
|
|
451
|
-
return function (a0, a1, a2, a3, a4, a5, a6) {
|
|
452
|
-
return fn.apply(this, arguments);
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
case 8:
|
|
456
|
-
return function (a0, a1, a2, a3, a4, a5, a6, a7) {
|
|
457
|
-
return fn.apply(this, arguments);
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
case 9:
|
|
461
|
-
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) {
|
|
462
|
-
return fn.apply(this, arguments);
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
case 10:
|
|
466
|
-
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
|
467
|
-
return fn.apply(this, arguments);
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
default:
|
|
471
|
-
throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
function _pipe(f, g) {
|
|
475
|
-
return function () {
|
|
476
|
-
return g.call(this, f.apply(this, arguments));
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
function pipe() {
|
|
480
|
-
if (arguments.length === 0) {
|
|
481
|
-
throw new Error('pipe requires at least one argument');
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
return _arity(arguments[0].length, reduceFn(_pipe, arguments[0], Array.prototype.slice.call(arguments, 1, Infinity)));
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
function compose() {
|
|
488
|
-
if (arguments.length === 0) {
|
|
489
|
-
throw new Error('compose requires at least one argument');
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
return pipe.apply(this, Array.prototype.slice.call(arguments, 0).reverse());
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
function concat(x, y) {
|
|
496
|
-
if (arguments.length === 1) return _y => concat(x, _y);
|
|
497
|
-
return typeof x === 'string' ? `${x}${y}` : [...x, ...y];
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
function cond(conditions) {
|
|
501
|
-
return input => {
|
|
502
|
-
let done = false;
|
|
503
|
-
let toReturn;
|
|
504
|
-
conditions.forEach(([predicate, resultClosure]) => {
|
|
505
|
-
if (!done && predicate(input)) {
|
|
506
|
-
done = true;
|
|
507
|
-
toReturn = resultClosure(input);
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
return toReturn;
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
const {
|
|
515
|
-
keys: keys$1
|
|
516
|
-
} = Object;
|
|
517
|
-
|
|
518
|
-
function mapArray(fn, list, isIndexed = false) {
|
|
519
|
-
let index = 0;
|
|
520
|
-
const willReturn = Array(list.length);
|
|
521
|
-
|
|
522
|
-
while (index < list.length) {
|
|
523
|
-
willReturn[index] = isIndexed ? fn(list[index], index) : fn(list[index]);
|
|
524
|
-
index++;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
return willReturn;
|
|
528
|
-
}
|
|
529
|
-
function mapObject(fn, obj) {
|
|
530
|
-
if (arguments.length === 1) {
|
|
531
|
-
return _obj => mapObject(fn, _obj);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
let index = 0;
|
|
535
|
-
const objKeys = keys$1(obj);
|
|
536
|
-
const len = objKeys.length;
|
|
537
|
-
const willReturn = {};
|
|
538
|
-
|
|
539
|
-
while (index < len) {
|
|
540
|
-
const key = objKeys[index];
|
|
541
|
-
willReturn[key] = fn(obj[key], key, obj);
|
|
542
|
-
index++;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
return willReturn;
|
|
546
|
-
}
|
|
547
|
-
const mapObjIndexed = mapObject;
|
|
548
|
-
function map(fn, iterable) {
|
|
549
|
-
if (arguments.length === 1) return _iterable => map(fn, _iterable);
|
|
550
|
-
|
|
551
|
-
if (!iterable) {
|
|
552
|
-
throw new Error(INCORRECT_ITERABLE_INPUT);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
if (isArray(iterable)) return mapArray(fn, iterable);
|
|
556
|
-
return mapObject(fn, iterable);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
function max(x, y) {
|
|
560
|
-
if (arguments.length === 1) return _y => max(x, _y);
|
|
561
|
-
return y > x ? y : x;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
function converge(fn, transformers) {
|
|
565
|
-
if (arguments.length === 1) return _transformers => converge(fn, _transformers);
|
|
566
|
-
const highestArity = reduce((a, b) => max(a, b.length), 0, transformers);
|
|
567
|
-
return curryN(highestArity, function () {
|
|
568
|
-
return fn.apply(this, map(g => g.apply(this, arguments), transformers));
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
function count(predicate, list) {
|
|
573
|
-
if (arguments.length === 1) {
|
|
574
|
-
return _list => count(predicate, _list);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
if (!isArray(list)) return 0;
|
|
578
|
-
return list.filter(x => predicate(x)).length;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
function countBy(fn, list) {
|
|
582
|
-
if (arguments.length === 1) {
|
|
583
|
-
return _list => countBy(fn, _list);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
const willReturn = {};
|
|
587
|
-
list.forEach(item => {
|
|
588
|
-
const key = fn(item);
|
|
589
|
-
|
|
590
|
-
if (!willReturn[key]) {
|
|
591
|
-
willReturn[key] = 1;
|
|
592
|
-
} else {
|
|
593
|
-
willReturn[key]++;
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
return willReturn;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
const dec = x => x - 1;
|
|
600
|
-
|
|
601
|
-
function isFalsy(input) {
|
|
602
|
-
return input === undefined || input === null || Number.isNaN(input) === true;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
function defaultTo(defaultArgument, input) {
|
|
606
|
-
if (arguments.length === 1) {
|
|
607
|
-
return _input => defaultTo(defaultArgument, _input);
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
return isFalsy(input) ? defaultArgument : input;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
function type(input) {
|
|
614
|
-
if (input === null) {
|
|
615
|
-
return 'Null';
|
|
616
|
-
} else if (input === undefined) {
|
|
617
|
-
return 'Undefined';
|
|
618
|
-
} else if (Number.isNaN(input)) {
|
|
619
|
-
return 'NaN';
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
const typeResult = Object.prototype.toString.call(input).slice(8, -1);
|
|
623
|
-
return typeResult === 'AsyncFunction' ? 'Promise' : typeResult;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
function _lastIndexOf(valueToFind, list) {
|
|
627
|
-
if (!isArray(list)) {
|
|
628
|
-
throw new Error(`Cannot read property 'indexOf' of ${list}`);
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
const typeOfValue = type(valueToFind);
|
|
632
|
-
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue)) return list.lastIndexOf(valueToFind);
|
|
633
|
-
const {
|
|
634
|
-
length
|
|
635
|
-
} = list;
|
|
636
|
-
let index = length;
|
|
637
|
-
let foundIndex = -1;
|
|
638
|
-
|
|
639
|
-
while (--index > -1 && foundIndex === -1) {
|
|
640
|
-
if (equals(list[index], valueToFind)) {
|
|
641
|
-
foundIndex = index;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
return foundIndex;
|
|
646
|
-
}
|
|
647
|
-
function _indexOf(valueToFind, list) {
|
|
648
|
-
if (!isArray(list)) {
|
|
649
|
-
throw new Error(`Cannot read property 'indexOf' of ${list}`);
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
const typeOfValue = type(valueToFind);
|
|
653
|
-
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue)) return list.indexOf(valueToFind);
|
|
654
|
-
let index = -1;
|
|
655
|
-
let foundIndex = -1;
|
|
656
|
-
const {
|
|
657
|
-
length
|
|
658
|
-
} = list;
|
|
659
|
-
|
|
660
|
-
while (++index < length && foundIndex === -1) {
|
|
661
|
-
if (equals(list[index], valueToFind)) {
|
|
662
|
-
foundIndex = index;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
return foundIndex;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
function _arrayFromIterator(iter) {
|
|
670
|
-
const list = [];
|
|
671
|
-
let next;
|
|
672
|
-
|
|
673
|
-
while (!(next = iter.next()).done) {
|
|
674
|
-
list.push(next.value);
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
return list;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
function _equalsSets(a, b) {
|
|
681
|
-
if (a.size !== b.size) {
|
|
682
|
-
return false;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
const aList = _arrayFromIterator(a.values());
|
|
686
|
-
|
|
687
|
-
const bList = _arrayFromIterator(b.values());
|
|
688
|
-
|
|
689
|
-
const filtered = aList.filter(aInstance => _indexOf(aInstance, bList) === -1);
|
|
690
|
-
return filtered.length === 0;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
function parseError(maybeError) {
|
|
694
|
-
const typeofError = maybeError.__proto__.toString();
|
|
695
|
-
|
|
696
|
-
if (!['Error', 'TypeError'].includes(typeofError)) return [];
|
|
697
|
-
return [typeofError, maybeError.message];
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
function parseDate(maybeDate) {
|
|
701
|
-
if (!maybeDate.toDateString) return [false];
|
|
702
|
-
return [true, maybeDate.getTime()];
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
function parseRegex(maybeRegex) {
|
|
706
|
-
if (maybeRegex.constructor !== RegExp) return [false];
|
|
707
|
-
return [true, maybeRegex.toString()];
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
function equals(a, b) {
|
|
711
|
-
if (arguments.length === 1) return _b => equals(a, _b);
|
|
712
|
-
const aType = type(a);
|
|
713
|
-
if (aType !== type(b)) return false;
|
|
714
|
-
|
|
715
|
-
if (aType === 'Function') {
|
|
716
|
-
return a.name === undefined ? false : a.name === b.name;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
if (['NaN', 'Undefined', 'Null'].includes(aType)) return true;
|
|
720
|
-
|
|
721
|
-
if (aType === 'Number') {
|
|
722
|
-
if (Object.is(-0, a) !== Object.is(-0, b)) return false;
|
|
723
|
-
return a.toString() === b.toString();
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
if (['String', 'Boolean'].includes(aType)) {
|
|
727
|
-
return a.toString() === b.toString();
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
if (aType === 'Array') {
|
|
731
|
-
const aClone = Array.from(a);
|
|
732
|
-
const bClone = Array.from(b);
|
|
733
|
-
|
|
734
|
-
if (aClone.toString() !== bClone.toString()) {
|
|
735
|
-
return false;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
let loopArrayFlag = true;
|
|
739
|
-
aClone.forEach((aCloneInstance, aCloneIndex) => {
|
|
740
|
-
if (loopArrayFlag) {
|
|
741
|
-
if (aCloneInstance !== bClone[aCloneIndex] && !equals(aCloneInstance, bClone[aCloneIndex])) {
|
|
742
|
-
loopArrayFlag = false;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
});
|
|
746
|
-
return loopArrayFlag;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
const aRegex = parseRegex(a);
|
|
750
|
-
const bRegex = parseRegex(b);
|
|
751
|
-
|
|
752
|
-
if (aRegex[0]) {
|
|
753
|
-
return bRegex[0] ? aRegex[1] === bRegex[1] : false;
|
|
754
|
-
} else if (bRegex[0]) return false;
|
|
755
|
-
|
|
756
|
-
const aDate = parseDate(a);
|
|
757
|
-
const bDate = parseDate(b);
|
|
758
|
-
|
|
759
|
-
if (aDate[0]) {
|
|
760
|
-
return bDate[0] ? aDate[1] === bDate[1] : false;
|
|
761
|
-
} else if (bDate[0]) return false;
|
|
762
|
-
|
|
763
|
-
const aError = parseError(a);
|
|
764
|
-
const bError = parseError(b);
|
|
765
|
-
|
|
766
|
-
if (aError[0]) {
|
|
767
|
-
return bError[0] ? aError[0] === bError[0] && aError[1] === bError[1] : false;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
if (aType === 'Set') {
|
|
771
|
-
return _equalsSets(a, b);
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
if (aType === 'Object') {
|
|
775
|
-
const aKeys = Object.keys(a);
|
|
776
|
-
|
|
777
|
-
if (aKeys.length !== Object.keys(b).length) {
|
|
778
|
-
return false;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
let loopObjectFlag = true;
|
|
782
|
-
aKeys.forEach(aKeyInstance => {
|
|
783
|
-
if (loopObjectFlag) {
|
|
784
|
-
const aValue = a[aKeyInstance];
|
|
785
|
-
const bValue = b[aKeyInstance];
|
|
786
|
-
|
|
787
|
-
if (aValue !== bValue && !equals(aValue, bValue)) {
|
|
788
|
-
loopObjectFlag = false;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
return loopObjectFlag;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
return false;
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
function includes(valueToFind, iterable) {
|
|
799
|
-
if (arguments.length === 1) return _iterable => includes(valueToFind, _iterable);
|
|
800
|
-
|
|
801
|
-
if (typeof iterable === 'string') {
|
|
802
|
-
return iterable.includes(valueToFind);
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
if (!iterable) {
|
|
806
|
-
throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`);
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
if (!isArray(iterable)) return false;
|
|
810
|
-
return _indexOf(valueToFind, iterable) > -1;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
class _Set {
|
|
814
|
-
constructor() {
|
|
815
|
-
this.set = new Set();
|
|
816
|
-
this.items = {};
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
checkUniqueness(item) {
|
|
820
|
-
const type$1 = type(item);
|
|
821
|
-
|
|
822
|
-
if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
|
|
823
|
-
if (type$1 in this.items) {
|
|
824
|
-
return false;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
this.items[type$1] = true;
|
|
828
|
-
return true;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
if (!['Object', 'Array'].includes(type$1)) {
|
|
832
|
-
const prevSize = this.set.size;
|
|
833
|
-
this.set.add(item);
|
|
834
|
-
return this.set.size !== prevSize;
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
if (!(type$1 in this.items)) {
|
|
838
|
-
this.items[type$1] = [item];
|
|
839
|
-
return true;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
if (_indexOf(item, this.items[type$1]) === -1) {
|
|
843
|
-
this.items[type$1].push(item);
|
|
844
|
-
return true;
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
return false;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
function uniq(list) {
|
|
853
|
-
const set = new _Set();
|
|
854
|
-
const willReturn = [];
|
|
855
|
-
list.forEach(item => {
|
|
856
|
-
if (set.checkUniqueness(item)) {
|
|
857
|
-
willReturn.push(item);
|
|
858
|
-
}
|
|
859
|
-
});
|
|
860
|
-
return willReturn;
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
function difference(a, b) {
|
|
864
|
-
if (arguments.length === 1) return _b => difference(a, _b);
|
|
865
|
-
return uniq(a).filter(aInstance => !includes(aInstance, b));
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
function dissoc(prop, obj) {
|
|
869
|
-
if (arguments.length === 1) return _obj => dissoc(prop, _obj);
|
|
870
|
-
if (obj === null || obj === undefined) return {};
|
|
871
|
-
const willReturn = {};
|
|
872
|
-
|
|
873
|
-
for (const p in obj) {
|
|
874
|
-
willReturn[p] = obj[p];
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
delete willReturn[prop];
|
|
878
|
-
return willReturn;
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
function divide(a, b) {
|
|
882
|
-
if (arguments.length === 1) return _b => divide(a, _b);
|
|
883
|
-
return a / b;
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
function drop(howManyToDrop, listOrString) {
|
|
887
|
-
if (arguments.length === 1) return _list => drop(howManyToDrop, _list);
|
|
888
|
-
return listOrString.slice(howManyToDrop > 0 ? howManyToDrop : 0);
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
function dropLast(howManyToDrop, listOrString) {
|
|
892
|
-
if (arguments.length === 1) {
|
|
893
|
-
return _listOrString => dropLast(howManyToDrop, _listOrString);
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
return howManyToDrop > 0 ? listOrString.slice(0, -howManyToDrop) : listOrString.slice();
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
function dropLastWhile(predicate, iterable) {
|
|
900
|
-
if (arguments.length === 1) {
|
|
901
|
-
return _iterable => dropLastWhile(predicate, _iterable);
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
if (iterable.length === 0) return iterable;
|
|
905
|
-
const isArray$1 = isArray(iterable);
|
|
906
|
-
|
|
907
|
-
if (typeof predicate !== 'function') {
|
|
908
|
-
throw new Error(`'predicate' is from wrong type ${typeof predicate}`);
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
if (!isArray$1 && typeof iterable !== 'string') {
|
|
912
|
-
throw new Error(`'iterable' is from wrong type ${typeof iterable}`);
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
let found = false;
|
|
916
|
-
const toReturn = [];
|
|
917
|
-
let counter = iterable.length;
|
|
918
|
-
|
|
919
|
-
while (counter > 0) {
|
|
920
|
-
counter--;
|
|
921
|
-
|
|
922
|
-
if (!found && predicate(iterable[counter]) === false) {
|
|
923
|
-
found = true;
|
|
924
|
-
toReturn.push(iterable[counter]);
|
|
925
|
-
} else if (found) {
|
|
926
|
-
toReturn.push(iterable[counter]);
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
return isArray$1 ? toReturn.reverse() : toReturn.reverse().join('');
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
function dropRepeats(list) {
|
|
934
|
-
if (!isArray(list)) {
|
|
935
|
-
throw new Error(`${list} is not a list`);
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
const toReturn = [];
|
|
939
|
-
list.reduce((prev, current) => {
|
|
940
|
-
if (!equals(prev, current)) {
|
|
941
|
-
toReturn.push(current);
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
return current;
|
|
945
|
-
}, undefined);
|
|
946
|
-
return toReturn;
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
function dropRepeatsWith(predicate, list) {
|
|
950
|
-
if (arguments.length === 1) {
|
|
951
|
-
return _iterable => dropRepeatsWith(predicate, _iterable);
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
if (!isArray(list)) {
|
|
955
|
-
throw new Error(`${list} is not a list`);
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
const toReturn = [];
|
|
959
|
-
list.reduce((prev, current) => {
|
|
960
|
-
if (prev === undefined) {
|
|
961
|
-
toReturn.push(current);
|
|
962
|
-
return current;
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
if (!predicate(prev, current)) {
|
|
966
|
-
toReturn.push(current);
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
return current;
|
|
970
|
-
}, undefined);
|
|
971
|
-
return toReturn;
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
function dropWhile(predicate, iterable) {
|
|
975
|
-
if (arguments.length === 1) {
|
|
976
|
-
return _iterable => dropWhile(predicate, _iterable);
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
const isArray$1 = isArray(iterable);
|
|
980
|
-
|
|
981
|
-
if (!isArray$1 && typeof iterable !== 'string') {
|
|
982
|
-
throw new Error('`iterable` is neither list nor a string');
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
let flag = false;
|
|
986
|
-
const holder = [];
|
|
987
|
-
let counter = -1;
|
|
988
|
-
|
|
989
|
-
while (counter++ < iterable.length - 1) {
|
|
990
|
-
if (flag) {
|
|
991
|
-
holder.push(iterable[counter]);
|
|
992
|
-
} else if (!predicate(iterable[counter])) {
|
|
993
|
-
if (!flag) flag = true;
|
|
994
|
-
holder.push(iterable[counter]);
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
return isArray$1 ? holder : holder.join('');
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
function either(firstPredicate, secondPredicate) {
|
|
1002
|
-
if (arguments.length === 1) {
|
|
1003
|
-
return _secondPredicate => either(firstPredicate, _secondPredicate);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
return (...input) => Boolean(firstPredicate(...input) || secondPredicate(...input));
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
function endsWith(target, iterable) {
|
|
1010
|
-
if (arguments.length === 1) return _iterable => endsWith(target, _iterable);
|
|
1011
|
-
|
|
1012
|
-
if (typeof iterable === 'string') {
|
|
1013
|
-
return iterable.endsWith(target);
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
if (!isArray(target)) return false;
|
|
1017
|
-
const diff = iterable.length - target.length;
|
|
1018
|
-
let correct = true;
|
|
1019
|
-
const filtered = target.filter((x, index) => {
|
|
1020
|
-
if (!correct) return false;
|
|
1021
|
-
const result = equals(x, iterable[index + diff]);
|
|
1022
|
-
if (!result) correct = false;
|
|
1023
|
-
return result;
|
|
1024
|
-
});
|
|
1025
|
-
return filtered.length === target.length;
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
function prop(propToFind, obj) {
|
|
1029
|
-
if (arguments.length === 1) return _obj => prop(propToFind, _obj);
|
|
1030
|
-
if (!obj) return undefined;
|
|
1031
|
-
return obj[propToFind];
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
function eqPropsFn(property, objA, objB) {
|
|
1035
|
-
return equals(prop(property, objA), prop(property, objB));
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
const eqProps = curry(eqPropsFn);
|
|
1039
|
-
|
|
1040
|
-
function evolveArray(rules, list) {
|
|
1041
|
-
return mapArray((x, i) => {
|
|
1042
|
-
if (type(rules[i]) === 'Function') {
|
|
1043
|
-
return rules[i](x);
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
return x;
|
|
1047
|
-
}, list, true);
|
|
1048
|
-
}
|
|
1049
|
-
function evolveObject(rules, iterable) {
|
|
1050
|
-
return mapObject((x, prop) => {
|
|
1051
|
-
if (type(x) === 'Object') {
|
|
1052
|
-
const typeRule = type(rules[prop]);
|
|
1053
|
-
|
|
1054
|
-
if (typeRule === 'Function') {
|
|
1055
|
-
return rules[prop](x);
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
if (typeRule === 'Object') {
|
|
1059
|
-
return evolve(rules[prop], x);
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
return x;
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
if (type(rules[prop]) === 'Function') {
|
|
1066
|
-
return rules[prop](x);
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
return x;
|
|
1070
|
-
}, iterable);
|
|
1071
|
-
}
|
|
1072
|
-
function evolve(rules, iterable) {
|
|
1073
|
-
if (arguments.length === 1) {
|
|
1074
|
-
return _iterable => evolve(rules, _iterable);
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
const rulesType = type(rules);
|
|
1078
|
-
const iterableType = type(iterable);
|
|
1079
|
-
|
|
1080
|
-
if (iterableType !== rulesType) {
|
|
1081
|
-
throw new Error('iterableType !== rulesType');
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
if (!['Object', 'Array'].includes(rulesType)) {
|
|
1085
|
-
throw new Error(`'iterable' and 'rules' are from wrong type ${rulesType}`);
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
if (iterableType === 'Object') {
|
|
1089
|
-
return evolveObject(rules, iterable);
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
return evolveArray(rules, iterable);
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
function filterObject(predicate, obj) {
|
|
1096
|
-
const willReturn = {};
|
|
1097
|
-
|
|
1098
|
-
for (const prop in obj) {
|
|
1099
|
-
if (predicate(obj[prop], prop, obj)) {
|
|
1100
|
-
willReturn[prop] = obj[prop];
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
return willReturn;
|
|
1105
|
-
}
|
|
1106
|
-
function filterArray(predicate, list, indexed = false) {
|
|
1107
|
-
let index = 0;
|
|
1108
|
-
const len = list.length;
|
|
1109
|
-
const willReturn = [];
|
|
1110
|
-
|
|
1111
|
-
while (index < len) {
|
|
1112
|
-
const predicateResult = indexed ? predicate(list[index], index) : predicate(list[index]);
|
|
1113
|
-
|
|
1114
|
-
if (predicateResult) {
|
|
1115
|
-
willReturn.push(list[index]);
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
index++;
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
return willReturn;
|
|
1122
|
-
}
|
|
1123
|
-
function filter(predicate, iterable) {
|
|
1124
|
-
if (arguments.length === 1) return _iterable => filter(predicate, _iterable);
|
|
1125
|
-
|
|
1126
|
-
if (!iterable) {
|
|
1127
|
-
throw new Error('Incorrect iterable input');
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
if (isArray(iterable)) return filterArray(predicate, iterable, false);
|
|
1131
|
-
return filterObject(predicate, iterable);
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
function find(predicate, list) {
|
|
1135
|
-
if (arguments.length === 1) return _list => find(predicate, _list);
|
|
1136
|
-
let index = 0;
|
|
1137
|
-
const len = list.length;
|
|
1138
|
-
|
|
1139
|
-
while (index < len) {
|
|
1140
|
-
const x = list[index];
|
|
1141
|
-
|
|
1142
|
-
if (predicate(x)) {
|
|
1143
|
-
return x;
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
index++;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
function findIndex(predicate, list) {
|
|
1151
|
-
if (arguments.length === 1) return _list => findIndex(predicate, _list);
|
|
1152
|
-
const len = list.length;
|
|
1153
|
-
let index = -1;
|
|
1154
|
-
|
|
1155
|
-
while (++index < len) {
|
|
1156
|
-
if (predicate(list[index])) {
|
|
1157
|
-
return index;
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
return -1;
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
function findLast(predicate, list) {
|
|
1165
|
-
if (arguments.length === 1) return _list => findLast(predicate, _list);
|
|
1166
|
-
let index = list.length;
|
|
1167
|
-
|
|
1168
|
-
while (--index >= 0) {
|
|
1169
|
-
if (predicate(list[index])) {
|
|
1170
|
-
return list[index];
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
return undefined;
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
function findLastIndex(fn, list) {
|
|
1178
|
-
if (arguments.length === 1) return _list => findLastIndex(fn, _list);
|
|
1179
|
-
let index = list.length;
|
|
1180
|
-
|
|
1181
|
-
while (--index >= 0) {
|
|
1182
|
-
if (fn(list[index])) {
|
|
1183
|
-
return index;
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
return -1;
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
function flatten(list, input) {
|
|
1191
|
-
const willReturn = input === undefined ? [] : input;
|
|
1192
|
-
|
|
1193
|
-
for (let i = 0; i < list.length; i++) {
|
|
1194
|
-
if (isArray(list[i])) {
|
|
1195
|
-
flatten(list[i], willReturn);
|
|
1196
|
-
} else {
|
|
1197
|
-
willReturn.push(list[i]);
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
return willReturn;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
function flipFn(fn) {
|
|
1205
|
-
return (...input) => {
|
|
1206
|
-
if (input.length === 1) {
|
|
1207
|
-
return holder => fn(holder, input[0]);
|
|
1208
|
-
} else if (input.length === 2) {
|
|
1209
|
-
return fn(input[1], input[0]);
|
|
1210
|
-
} else if (input.length === 3) {
|
|
1211
|
-
return fn(input[1], input[0], input[2]);
|
|
1212
|
-
} else if (input.length === 4) {
|
|
1213
|
-
return fn(input[1], input[0], input[2], input[3]);
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
throw new Error('R.flip doesn\'t work with arity > 4');
|
|
1217
|
-
};
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
function flip(fn) {
|
|
1221
|
-
return flipFn(fn);
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
function forEach(fn, list) {
|
|
1225
|
-
if (arguments.length === 1) return _list => forEach(fn, _list);
|
|
1226
|
-
|
|
1227
|
-
if (list === undefined) {
|
|
1228
|
-
return;
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
if (isArray(list)) {
|
|
1232
|
-
let index = 0;
|
|
1233
|
-
const len = list.length;
|
|
1234
|
-
|
|
1235
|
-
while (index < len) {
|
|
1236
|
-
fn(list[index]);
|
|
1237
|
-
index++;
|
|
1238
|
-
}
|
|
1239
|
-
} else {
|
|
1240
|
-
let index = 0;
|
|
1241
|
-
const listKeys = keys$1(list);
|
|
1242
|
-
const len = listKeys.length;
|
|
1243
|
-
|
|
1244
|
-
while (index < len) {
|
|
1245
|
-
const key = listKeys[index];
|
|
1246
|
-
fn(list[key], key, list);
|
|
1247
|
-
index++;
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
return list;
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
function fromPairs(listOfPairs) {
|
|
1255
|
-
const toReturn = {};
|
|
1256
|
-
listOfPairs.forEach(([prop, value]) => toReturn[prop] = value);
|
|
1257
|
-
return toReturn;
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
function groupBy(groupFn, list) {
|
|
1261
|
-
if (arguments.length === 1) return _list => groupBy(groupFn, _list);
|
|
1262
|
-
const result = {};
|
|
1263
|
-
|
|
1264
|
-
for (let i = 0; i < list.length; i++) {
|
|
1265
|
-
const item = list[i];
|
|
1266
|
-
const key = groupFn(item);
|
|
1267
|
-
|
|
1268
|
-
if (!result[key]) {
|
|
1269
|
-
result[key] = [];
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
result[key].push(item);
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
return result;
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
function groupWith(compareFn, list) {
|
|
1279
|
-
if (!isArray(list)) throw new TypeError('list.reduce is not a function');
|
|
1280
|
-
const clone = cloneList(list);
|
|
1281
|
-
if (list.length === 1) return [clone];
|
|
1282
|
-
const toReturn = [];
|
|
1283
|
-
let holder = [];
|
|
1284
|
-
clone.reduce((prev, current, i) => {
|
|
1285
|
-
if (i === 0) return current;
|
|
1286
|
-
const okCompare = compareFn(prev, current);
|
|
1287
|
-
const holderIsEmpty = holder.length === 0;
|
|
1288
|
-
const lastCall = i === list.length - 1;
|
|
1289
|
-
|
|
1290
|
-
if (okCompare) {
|
|
1291
|
-
if (holderIsEmpty) holder.push(prev);
|
|
1292
|
-
holder.push(current);
|
|
1293
|
-
if (lastCall) toReturn.push(holder);
|
|
1294
|
-
return current;
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
if (holderIsEmpty) {
|
|
1298
|
-
toReturn.push([prev]);
|
|
1299
|
-
if (lastCall) toReturn.push([current]);
|
|
1300
|
-
return current;
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
toReturn.push(holder);
|
|
1304
|
-
if (lastCall) toReturn.push([current]);
|
|
1305
|
-
holder = [];
|
|
1306
|
-
return current;
|
|
1307
|
-
}, undefined);
|
|
1308
|
-
return toReturn;
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
function has(prop, obj) {
|
|
1312
|
-
if (arguments.length === 1) return _obj => has(prop, _obj);
|
|
1313
|
-
if (!obj) return false;
|
|
1314
|
-
return obj.hasOwnProperty(prop);
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
function createPath(path, delimiter = '.') {
|
|
1318
|
-
return typeof path === 'string' ? path.split(delimiter) : path;
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
function path(pathInput, obj) {
|
|
1322
|
-
if (arguments.length === 1) return _obj => path(pathInput, _obj);
|
|
1323
|
-
|
|
1324
|
-
if (obj === null || obj === undefined) {
|
|
1325
|
-
return undefined;
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
let willReturn = obj;
|
|
1329
|
-
let counter = 0;
|
|
1330
|
-
const pathArrValue = createPath(pathInput);
|
|
1331
|
-
|
|
1332
|
-
while (counter < pathArrValue.length) {
|
|
1333
|
-
if (willReturn === null || willReturn === undefined) {
|
|
1334
|
-
return undefined;
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
if (willReturn[pathArrValue[counter]] === null) return undefined;
|
|
1338
|
-
willReturn = willReturn[pathArrValue[counter]];
|
|
1339
|
-
counter++;
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
return willReturn;
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
function hasPath(pathInput, obj) {
|
|
1346
|
-
if (arguments.length === 1) {
|
|
1347
|
-
return objHolder => hasPath(pathInput, objHolder);
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
return path(pathInput, obj) !== undefined;
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
function head(listOrString) {
|
|
1354
|
-
if (typeof listOrString === 'string') return listOrString[0] || '';
|
|
1355
|
-
return listOrString[0];
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
function _objectIs(a, b) {
|
|
1359
|
-
if (a === b) {
|
|
1360
|
-
return a !== 0 || 1 / a === 1 / b;
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
return a !== a && b !== b;
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
|
-
const objectIs = Object.is || _objectIs;
|
|
1367
|
-
|
|
1368
|
-
function identical(a, b) {
|
|
1369
|
-
if (arguments.length === 1) return _b => identical(a, _b);
|
|
1370
|
-
return objectIs(a, b);
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
function identity(x) {
|
|
1374
|
-
return x;
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
function ifElseFn(condition, onTrue, onFalse) {
|
|
1378
|
-
return (...input) => {
|
|
1379
|
-
const conditionResult = typeof condition === 'boolean' ? condition : condition(...input);
|
|
1380
|
-
|
|
1381
|
-
if (conditionResult === true) {
|
|
1382
|
-
return onTrue(...input);
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
return onFalse(...input);
|
|
1386
|
-
};
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
const ifElse = curry(ifElseFn);
|
|
1390
|
-
|
|
1391
|
-
const inc = x => x + 1;
|
|
1392
|
-
|
|
1393
|
-
function indexByPath(pathInput, list) {
|
|
1394
|
-
const toReturn = {};
|
|
1395
|
-
|
|
1396
|
-
for (let i = 0; i < list.length; i++) {
|
|
1397
|
-
const item = list[i];
|
|
1398
|
-
toReturn[path(pathInput, item)] = item;
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
return toReturn;
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
function indexBy(condition, list) {
|
|
1405
|
-
if (arguments.length === 1) {
|
|
1406
|
-
return _list => indexBy(condition, _list);
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
if (typeof condition === 'string') {
|
|
1410
|
-
return indexByPath(condition, list);
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
|
-
const toReturn = {};
|
|
1414
|
-
|
|
1415
|
-
for (let i = 0; i < list.length; i++) {
|
|
1416
|
-
const item = list[i];
|
|
1417
|
-
toReturn[condition(item)] = item;
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
return toReturn;
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
function indexOf(valueToFind, list) {
|
|
1424
|
-
if (arguments.length === 1) {
|
|
1425
|
-
return _list => _indexOf(valueToFind, _list);
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
return _indexOf(valueToFind, list);
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
function baseSlice(array, start, end) {
|
|
1432
|
-
let index = -1;
|
|
1433
|
-
let {
|
|
1434
|
-
length
|
|
1435
|
-
} = array;
|
|
1436
|
-
end = end > length ? length : end;
|
|
1437
|
-
|
|
1438
|
-
if (end < 0) {
|
|
1439
|
-
end += length;
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
length = start > end ? 0 : end - start >>> 0;
|
|
1443
|
-
start >>>= 0;
|
|
1444
|
-
const result = Array(length);
|
|
1445
|
-
|
|
1446
|
-
while (++index < length) {
|
|
1447
|
-
result[index] = array[index + start];
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
return result;
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
function init(listOrString) {
|
|
1454
|
-
if (typeof listOrString === 'string') return listOrString.slice(0, -1);
|
|
1455
|
-
return listOrString.length ? baseSlice(listOrString, 0, -1) : [];
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
function intersection(listA, listB) {
|
|
1459
|
-
if (arguments.length === 1) return _list => intersection(listA, _list);
|
|
1460
|
-
return filter(x => includes(x, listA), listB);
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
function intersperse(separator, list) {
|
|
1464
|
-
if (arguments.length === 1) return _list => intersperse(separator, _list);
|
|
1465
|
-
let index = -1;
|
|
1466
|
-
const len = list.length;
|
|
1467
|
-
const willReturn = [];
|
|
1468
|
-
|
|
1469
|
-
while (++index < len) {
|
|
1470
|
-
if (index === len - 1) {
|
|
1471
|
-
willReturn.push(list[index]);
|
|
1472
|
-
} else {
|
|
1473
|
-
willReturn.push(list[index], separator);
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
return willReturn;
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
function is(targetPrototype, x) {
|
|
1481
|
-
if (arguments.length === 1) return _x => is(targetPrototype, _x);
|
|
1482
|
-
return x != null && x.constructor === targetPrototype || x instanceof targetPrototype;
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1485
|
-
function isEmpty(input) {
|
|
1486
|
-
const inputType = type(input);
|
|
1487
|
-
if (['Undefined', 'NaN', 'Number', 'Null'].includes(inputType)) return false;
|
|
1488
|
-
if (!input) return true;
|
|
1489
|
-
|
|
1490
|
-
if (inputType === 'Object') {
|
|
1491
|
-
return Object.keys(input).length === 0;
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
if (inputType === 'Array') {
|
|
1495
|
-
return input.length === 0;
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
return false;
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
function isNil(x) {
|
|
1502
|
-
return x === undefined || x === null;
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
function join(glue, list) {
|
|
1506
|
-
if (arguments.length === 1) return _list => join(glue, _list);
|
|
1507
|
-
return list.join(glue);
|
|
1508
|
-
}
|
|
1509
|
-
|
|
1510
|
-
function juxt(listOfFunctions) {
|
|
1511
|
-
return (...args) => listOfFunctions.map(fn => fn(...args));
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1514
|
-
function keys(x) {
|
|
1515
|
-
return Object.keys(x);
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
function last(listOrString) {
|
|
1519
|
-
if (typeof listOrString === 'string') {
|
|
1520
|
-
return listOrString[listOrString.length - 1] || '';
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
return listOrString[listOrString.length - 1];
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
function lastIndexOf(valueToFind, list) {
|
|
1527
|
-
if (arguments.length === 1) {
|
|
1528
|
-
return _list => _lastIndexOf(valueToFind, _list);
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
return _lastIndexOf(valueToFind, list);
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
function length(x) {
|
|
1535
|
-
if (isArray(x)) return x.length;
|
|
1536
|
-
if (typeof x === 'string') return x.length;
|
|
1537
|
-
return NaN;
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1540
|
-
function lens(getter, setter) {
|
|
1541
|
-
return function (functor) {
|
|
1542
|
-
return function (target) {
|
|
1543
|
-
return functor(getter(target)).map(focus => setter(focus, target));
|
|
1544
|
-
};
|
|
1545
|
-
};
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
function nth(index, input) {
|
|
1549
|
-
if (arguments.length === 1) return _input => nth(index, _input);
|
|
1550
|
-
const idx = index < 0 ? input.length + index : index;
|
|
1551
|
-
return Object.prototype.toString.call(input) === '[object String]' ? input.charAt(idx) : input[idx];
|
|
1552
|
-
}
|
|
1553
|
-
|
|
1554
|
-
function updateFn(index, newValue, list) {
|
|
1555
|
-
const clone = cloneList(list);
|
|
1556
|
-
if (index === -1) return clone.fill(newValue, index);
|
|
1557
|
-
return clone.fill(newValue, index, index + 1);
|
|
1558
|
-
}
|
|
1559
|
-
const update = curry(updateFn);
|
|
1560
|
-
|
|
1561
|
-
function lensIndex(index) {
|
|
1562
|
-
return lens(nth(index), update(index));
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
function lensPath(key) {
|
|
1566
|
-
return lens(path(key), assocPath(key));
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
function lensProp(key) {
|
|
1570
|
-
return lens(prop(key), assoc(key));
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
function match(pattern, input) {
|
|
1574
|
-
if (arguments.length === 1) return _input => match(pattern, _input);
|
|
1575
|
-
const willReturn = input.match(pattern);
|
|
1576
|
-
return willReturn === null ? [] : willReturn;
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
function mathMod(x, y) {
|
|
1580
|
-
if (arguments.length === 1) return _y => mathMod(x, _y);
|
|
1581
|
-
if (!isInteger(x) || !isInteger(y) || y < 1) return NaN;
|
|
1582
|
-
return (x % y + y) % y;
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
function maxByFn(compareFn, x, y) {
|
|
1586
|
-
return compareFn(y) > compareFn(x) ? y : x;
|
|
1587
|
-
}
|
|
1588
|
-
const maxBy = curry(maxByFn);
|
|
1589
|
-
|
|
1590
|
-
function sum(list) {
|
|
1591
|
-
return list.reduce((prev, current) => prev + current, 0);
|
|
1592
|
-
}
|
|
1593
|
-
|
|
1594
|
-
function mean(list) {
|
|
1595
|
-
return sum(list) / list.length;
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
function median(list) {
|
|
1599
|
-
const len = list.length;
|
|
1600
|
-
if (len === 0) return NaN;
|
|
1601
|
-
const width = 2 - len % 2;
|
|
1602
|
-
const idx = (len - width) / 2;
|
|
1603
|
-
return mean(Array.prototype.slice.call(list, 0).sort((a, b) => {
|
|
1604
|
-
if (a === b) return 0;
|
|
1605
|
-
return a < b ? -1 : 1;
|
|
1606
|
-
}).slice(idx, idx + width));
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
function mergeRight(target, newProps) {
|
|
1610
|
-
if (arguments.length === 1) return _newProps => mergeRight(target, _newProps);
|
|
1611
|
-
return Object.assign({}, target || {}, newProps || {});
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
function mergeAll(arr) {
|
|
1615
|
-
let willReturn = {};
|
|
1616
|
-
map(val => {
|
|
1617
|
-
willReturn = mergeRight(willReturn, val);
|
|
1618
|
-
}, arr);
|
|
1619
|
-
return willReturn;
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
function mergeDeepRight(target, source) {
|
|
1623
|
-
if (arguments.length === 1) {
|
|
1624
|
-
return sourceHolder => mergeDeepRight(target, sourceHolder);
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
const willReturn = clone(target);
|
|
1628
|
-
Object.keys(source).forEach(key => {
|
|
1629
|
-
if (type(source[key]) === 'Object') {
|
|
1630
|
-
if (type(target[key]) === 'Object') {
|
|
1631
|
-
willReturn[key] = mergeDeepRight(target[key], source[key]);
|
|
1632
|
-
} else {
|
|
1633
|
-
willReturn[key] = source[key];
|
|
1634
|
-
}
|
|
1635
|
-
} else {
|
|
1636
|
-
willReturn[key] = source[key];
|
|
1637
|
-
}
|
|
1638
|
-
});
|
|
1639
|
-
return willReturn;
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
function mergeLeft(x, y) {
|
|
1643
|
-
if (arguments.length === 1) return _y => mergeLeft(x, _y);
|
|
1644
|
-
return mergeRight(y, x);
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
function mergeWithFn(mergeFn, a, b) {
|
|
1648
|
-
const willReturn = {};
|
|
1649
|
-
Object.keys(a).forEach(key => {
|
|
1650
|
-
if (b[key] === undefined) {
|
|
1651
|
-
willReturn[key] = a[key];
|
|
1652
|
-
} else {
|
|
1653
|
-
willReturn[key] = mergeFn(a[key], b[key]);
|
|
1654
|
-
}
|
|
1655
|
-
});
|
|
1656
|
-
Object.keys(b).forEach(key => {
|
|
1657
|
-
if (willReturn[key] !== undefined) return;
|
|
1658
|
-
|
|
1659
|
-
if (a[key] === undefined) {
|
|
1660
|
-
willReturn[key] = b[key];
|
|
1661
|
-
} else {
|
|
1662
|
-
willReturn[key] = mergeFn(a[key], b[key]);
|
|
1663
|
-
}
|
|
1664
|
-
});
|
|
1665
|
-
return willReturn;
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
const mergeWith = curry(mergeWithFn);
|
|
1669
|
-
|
|
1670
|
-
function min(x, y) {
|
|
1671
|
-
if (arguments.length === 1) return _y => min(x, _y);
|
|
1672
|
-
return y < x ? y : x;
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
function minByFn(compareFn, x, y) {
|
|
1676
|
-
return compareFn(y) < compareFn(x) ? y : x;
|
|
1677
|
-
}
|
|
1678
|
-
const minBy = curry(minByFn);
|
|
1679
|
-
|
|
1680
|
-
function ownKeys(object, enumerableOnly) {
|
|
1681
|
-
var keys = Object.keys(object);
|
|
1682
|
-
|
|
1683
|
-
if (Object.getOwnPropertySymbols) {
|
|
1684
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
1685
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
1686
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
1687
|
-
})), keys.push.apply(keys, symbols);
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
return keys;
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
|
-
function _objectSpread2(target) {
|
|
1694
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
1695
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
1696
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
1697
|
-
_defineProperty(target, key, source[key]);
|
|
1698
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
1699
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
1700
|
-
});
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
return target;
|
|
1704
|
-
}
|
|
1705
|
-
|
|
1706
|
-
function _defineProperty(obj, key, value) {
|
|
1707
|
-
if (key in obj) {
|
|
1708
|
-
Object.defineProperty(obj, key, {
|
|
1709
|
-
value: value,
|
|
1710
|
-
enumerable: true,
|
|
1711
|
-
configurable: true,
|
|
1712
|
-
writable: true
|
|
1713
|
-
});
|
|
1714
|
-
} else {
|
|
1715
|
-
obj[key] = value;
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
return obj;
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
function isIterable(input) {
|
|
1722
|
-
return Array.isArray(input) || type(input) === 'Object';
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
function modifyFn(property, fn, iterable) {
|
|
1726
|
-
if (!isIterable(iterable)) return iterable;
|
|
1727
|
-
if (iterable[property] === undefined) return iterable;
|
|
1728
|
-
|
|
1729
|
-
if (isArray(iterable)) {
|
|
1730
|
-
return updateFn(property, fn(iterable[property]), iterable);
|
|
1731
|
-
}
|
|
1732
|
-
|
|
1733
|
-
return _objectSpread2(_objectSpread2({}, iterable), {}, {
|
|
1734
|
-
[property]: fn(iterable[property])
|
|
1735
|
-
});
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
const modify = curry(modifyFn);
|
|
1739
|
-
|
|
1740
|
-
function modifyPathFn(pathInput, fn, object) {
|
|
1741
|
-
const path$1 = createPath(pathInput);
|
|
1742
|
-
|
|
1743
|
-
if (path$1.length === 1) {
|
|
1744
|
-
return _objectSpread2(_objectSpread2({}, object), {}, {
|
|
1745
|
-
[path$1[0]]: fn(object[path$1[0]])
|
|
1746
|
-
});
|
|
1747
|
-
}
|
|
1748
|
-
|
|
1749
|
-
if (path(path$1, object) === undefined) return object;
|
|
1750
|
-
const val = modifyPath(Array.prototype.slice.call(path$1, 1), fn, object[path$1[0]]);
|
|
1751
|
-
|
|
1752
|
-
if (val === object[path$1[0]]) {
|
|
1753
|
-
return object;
|
|
1754
|
-
}
|
|
1755
|
-
|
|
1756
|
-
return assoc(path$1[0], val, object);
|
|
1757
|
-
}
|
|
1758
|
-
const modifyPath = curry(modifyPathFn);
|
|
1759
|
-
|
|
1760
|
-
function modulo(x, y) {
|
|
1761
|
-
if (arguments.length === 1) return _y => modulo(x, _y);
|
|
1762
|
-
return x % y;
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
function moveFn(fromIndex, toIndex, list) {
|
|
1766
|
-
if (fromIndex < 0 || toIndex < 0) {
|
|
1767
|
-
throw new Error('Rambda.move does not support negative indexes');
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
if (fromIndex > list.length - 1 || toIndex > list.length - 1) return list;
|
|
1771
|
-
const clone = cloneList(list);
|
|
1772
|
-
clone[fromIndex] = list[toIndex];
|
|
1773
|
-
clone[toIndex] = list[fromIndex];
|
|
1774
|
-
return clone;
|
|
1775
|
-
}
|
|
1776
|
-
|
|
1777
|
-
const move = curry(moveFn);
|
|
1778
|
-
|
|
1779
|
-
function multiply(x, y) {
|
|
1780
|
-
if (arguments.length === 1) return _y => multiply(x, _y);
|
|
1781
|
-
return x * y;
|
|
1782
|
-
}
|
|
1783
|
-
|
|
1784
|
-
function negate(x) {
|
|
1785
|
-
return -x;
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
function none(predicate, list) {
|
|
1789
|
-
if (arguments.length === 1) return _list => none(predicate, _list);
|
|
1790
|
-
|
|
1791
|
-
for (let i = 0; i < list.length; i++) {
|
|
1792
|
-
if (predicate(list[i])) return false;
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
return true;
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
function not(input) {
|
|
1799
|
-
return !input;
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
|
-
function objOf(key, value) {
|
|
1803
|
-
if (arguments.length === 1) {
|
|
1804
|
-
return _value => objOf(key, _value);
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
return {
|
|
1808
|
-
[key]: value
|
|
1809
|
-
};
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
function of(value) {
|
|
1813
|
-
return [value];
|
|
1814
|
-
}
|
|
1815
|
-
|
|
1816
|
-
function omit(propsToOmit, obj) {
|
|
1817
|
-
if (arguments.length === 1) return _obj => omit(propsToOmit, _obj);
|
|
1818
|
-
|
|
1819
|
-
if (obj === null || obj === undefined) {
|
|
1820
|
-
return undefined;
|
|
1821
|
-
}
|
|
1822
|
-
|
|
1823
|
-
const propsToOmitValue = createPath(propsToOmit, ',');
|
|
1824
|
-
const willReturn = {};
|
|
1825
|
-
|
|
1826
|
-
for (const key in obj) {
|
|
1827
|
-
if (!propsToOmitValue.includes(key)) {
|
|
1828
|
-
willReturn[key] = obj[key];
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
|
|
1832
|
-
return willReturn;
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
function on(binaryFn, unaryFn, a, b) {
|
|
1836
|
-
if (arguments.length === 3) {
|
|
1837
|
-
return _b => on(binaryFn, unaryFn, a, _b);
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
if (arguments.length === 2) {
|
|
1841
|
-
return (_a, _b) => on(binaryFn, unaryFn, _a, _b);
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
return binaryFn(unaryFn(a), unaryFn(b));
|
|
1845
|
-
}
|
|
1846
|
-
|
|
1847
|
-
function onceFn(fn, context) {
|
|
1848
|
-
let result;
|
|
1849
|
-
return function () {
|
|
1850
|
-
if (fn) {
|
|
1851
|
-
result = fn.apply(context || this, arguments);
|
|
1852
|
-
fn = null;
|
|
1853
|
-
}
|
|
1854
|
-
|
|
1855
|
-
return result;
|
|
1856
|
-
};
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
function once(fn, context) {
|
|
1860
|
-
if (arguments.length === 1) {
|
|
1861
|
-
const wrap = onceFn(fn, context);
|
|
1862
|
-
return curry(wrap);
|
|
1863
|
-
}
|
|
1864
|
-
|
|
1865
|
-
return onceFn(fn, context);
|
|
1866
|
-
}
|
|
1867
|
-
|
|
1868
|
-
function or(a, b) {
|
|
1869
|
-
if (arguments.length === 1) return _b => or(a, _b);
|
|
1870
|
-
return a || b;
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
const Identity = x => ({
|
|
1874
|
-
x,
|
|
1875
|
-
map: fn => Identity(fn(x))
|
|
1876
|
-
});
|
|
1877
|
-
|
|
1878
|
-
function overFn(lens, fn, object) {
|
|
1879
|
-
return lens(x => Identity(fn(x)))(object).x;
|
|
1880
|
-
}
|
|
1881
|
-
|
|
1882
|
-
const over = curry(overFn);
|
|
1883
|
-
|
|
1884
|
-
function partial(fn, ...args) {
|
|
1885
|
-
const len = fn.length;
|
|
1886
|
-
return (...rest) => {
|
|
1887
|
-
if (args.length + rest.length >= len) {
|
|
1888
|
-
return fn(...args, ...rest);
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
return partial(fn, ...[...args, ...rest]);
|
|
1892
|
-
};
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
function partialObject(fn, input) {
|
|
1896
|
-
return nextInput => fn(mergeDeepRight(nextInput, input));
|
|
1897
|
-
}
|
|
1898
|
-
|
|
1899
|
-
function partitionObject(predicate, iterable) {
|
|
1900
|
-
const yes = {};
|
|
1901
|
-
const no = {};
|
|
1902
|
-
Object.entries(iterable).forEach(([prop, value]) => {
|
|
1903
|
-
if (predicate(value, prop)) {
|
|
1904
|
-
yes[prop] = value;
|
|
1905
|
-
} else {
|
|
1906
|
-
no[prop] = value;
|
|
1907
|
-
}
|
|
1908
|
-
});
|
|
1909
|
-
return [yes, no];
|
|
1910
|
-
}
|
|
1911
|
-
function partitionArray(predicate, list, indexed = false) {
|
|
1912
|
-
const yes = [];
|
|
1913
|
-
const no = [];
|
|
1914
|
-
let counter = -1;
|
|
1915
|
-
|
|
1916
|
-
while (counter++ < list.length - 1) {
|
|
1917
|
-
if (indexed ? predicate(list[counter], counter) : predicate(list[counter])) {
|
|
1918
|
-
yes.push(list[counter]);
|
|
1919
|
-
} else {
|
|
1920
|
-
no.push(list[counter]);
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
|
-
return [yes, no];
|
|
1925
|
-
}
|
|
1926
|
-
function partition(predicate, iterable) {
|
|
1927
|
-
if (arguments.length === 1) {
|
|
1928
|
-
return listHolder => partition(predicate, listHolder);
|
|
1929
|
-
}
|
|
1930
|
-
|
|
1931
|
-
if (!isArray(iterable)) return partitionObject(predicate, iterable);
|
|
1932
|
-
return partitionArray(predicate, iterable);
|
|
1933
|
-
}
|
|
1934
|
-
|
|
1935
|
-
function pathEqFn(pathToSearch, target, input) {
|
|
1936
|
-
return equals(path(pathToSearch, input), target);
|
|
1937
|
-
}
|
|
1938
|
-
|
|
1939
|
-
const pathEq = curry(pathEqFn);
|
|
1940
|
-
|
|
1941
|
-
function pathOrFn(defaultValue, pathInput, obj) {
|
|
1942
|
-
return defaultTo(defaultValue, path(pathInput, obj));
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
|
-
const pathOr = curry(pathOrFn);
|
|
1946
|
-
|
|
1947
|
-
function paths(pathsToSearch, obj) {
|
|
1948
|
-
if (arguments.length === 1) {
|
|
1949
|
-
return _obj => paths(pathsToSearch, _obj);
|
|
1950
|
-
}
|
|
1951
|
-
|
|
1952
|
-
return pathsToSearch.map(singlePath => path(singlePath, obj));
|
|
1953
|
-
}
|
|
1954
|
-
|
|
1955
|
-
function pick(propsToPick, input) {
|
|
1956
|
-
if (arguments.length === 1) return _input => pick(propsToPick, _input);
|
|
1957
|
-
|
|
1958
|
-
if (input === null || input === undefined) {
|
|
1959
|
-
return undefined;
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
|
-
const keys = createPath(propsToPick, ',');
|
|
1963
|
-
const willReturn = {};
|
|
1964
|
-
let counter = 0;
|
|
1965
|
-
|
|
1966
|
-
while (counter < keys.length) {
|
|
1967
|
-
if (keys[counter] in input) {
|
|
1968
|
-
willReturn[keys[counter]] = input[keys[counter]];
|
|
1969
|
-
}
|
|
1970
|
-
|
|
1971
|
-
counter++;
|
|
1972
|
-
}
|
|
1973
|
-
|
|
1974
|
-
return willReturn;
|
|
1975
|
-
}
|
|
1976
|
-
|
|
1977
|
-
function pickAll(propsToPick, obj) {
|
|
1978
|
-
if (arguments.length === 1) return _obj => pickAll(propsToPick, _obj);
|
|
1979
|
-
|
|
1980
|
-
if (obj === null || obj === undefined) {
|
|
1981
|
-
return undefined;
|
|
1982
|
-
}
|
|
1983
|
-
|
|
1984
|
-
const keysValue = createPath(propsToPick, ',');
|
|
1985
|
-
const willReturn = {};
|
|
1986
|
-
let counter = 0;
|
|
1987
|
-
|
|
1988
|
-
while (counter < keysValue.length) {
|
|
1989
|
-
if (keysValue[counter] in obj) {
|
|
1990
|
-
willReturn[keysValue[counter]] = obj[keysValue[counter]];
|
|
1991
|
-
} else {
|
|
1992
|
-
willReturn[keysValue[counter]] = undefined;
|
|
1993
|
-
}
|
|
1994
|
-
|
|
1995
|
-
counter++;
|
|
1996
|
-
}
|
|
1997
|
-
|
|
1998
|
-
return willReturn;
|
|
1999
|
-
}
|
|
2000
|
-
|
|
2001
|
-
function pluck(property, list) {
|
|
2002
|
-
if (arguments.length === 1) return _list => pluck(property, _list);
|
|
2003
|
-
const willReturn = [];
|
|
2004
|
-
map(x => {
|
|
2005
|
-
if (x[property] !== undefined) {
|
|
2006
|
-
willReturn.push(x[property]);
|
|
2007
|
-
}
|
|
2008
|
-
}, list);
|
|
2009
|
-
return willReturn;
|
|
2010
|
-
}
|
|
2011
|
-
|
|
2012
|
-
function prepend(x, input) {
|
|
2013
|
-
if (arguments.length === 1) return _input => prepend(x, _input);
|
|
2014
|
-
if (typeof input === 'string') return [x].concat(input.split(''));
|
|
2015
|
-
return [x].concat(input);
|
|
2016
|
-
}
|
|
2017
|
-
|
|
2018
|
-
const product = reduce(multiply, 1);
|
|
2019
|
-
|
|
2020
|
-
function propEqFn(propToFind, valueToMatch, obj) {
|
|
2021
|
-
if (!obj) return false;
|
|
2022
|
-
return equals(valueToMatch, prop(propToFind, obj));
|
|
2023
|
-
}
|
|
2024
|
-
|
|
2025
|
-
const propEq = curry(propEqFn);
|
|
2026
|
-
|
|
2027
|
-
function propIsFn(targetPrototype, property, obj) {
|
|
2028
|
-
return is(targetPrototype, obj[property]);
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
|
-
const propIs = curry(propIsFn);
|
|
2032
|
-
|
|
2033
|
-
function propOrFn(defaultValue, property, obj) {
|
|
2034
|
-
if (!obj) return defaultValue;
|
|
2035
|
-
return defaultTo(defaultValue, obj[property]);
|
|
2036
|
-
}
|
|
2037
|
-
|
|
2038
|
-
const propOr = curry(propOrFn);
|
|
2039
|
-
|
|
2040
|
-
function propSatisfiesFn(predicate, property, obj) {
|
|
2041
|
-
return predicate(prop(property, obj));
|
|
2042
|
-
}
|
|
2043
|
-
|
|
2044
|
-
const propSatisfies = curry(propSatisfiesFn);
|
|
2045
|
-
|
|
2046
|
-
function props(propsToPick, obj) {
|
|
2047
|
-
if (arguments.length === 1) {
|
|
2048
|
-
return _obj => props(propsToPick, _obj);
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
if (!isArray(propsToPick)) {
|
|
2052
|
-
throw new Error('propsToPick is not a list');
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
return mapArray(prop => obj[prop], propsToPick);
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
function range(start, end) {
|
|
2059
|
-
if (arguments.length === 1) return _end => range(start, _end);
|
|
2060
|
-
|
|
2061
|
-
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
2062
|
-
throw new TypeError('Both arguments to range must be numbers');
|
|
2063
|
-
}
|
|
2064
|
-
|
|
2065
|
-
if (end < start) return [];
|
|
2066
|
-
const len = end - start;
|
|
2067
|
-
const willReturn = Array(len);
|
|
2068
|
-
|
|
2069
|
-
for (let i = 0; i < len; i++) {
|
|
2070
|
-
willReturn[i] = start + i;
|
|
2071
|
-
}
|
|
2072
|
-
|
|
2073
|
-
return willReturn;
|
|
2074
|
-
}
|
|
2075
|
-
|
|
2076
|
-
function reject(predicate, list) {
|
|
2077
|
-
if (arguments.length === 1) return _list => reject(predicate, _list);
|
|
2078
|
-
return filter(x => !predicate(x), list);
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
|
-
function repeat(x, timesToRepeat) {
|
|
2082
|
-
if (arguments.length === 1) {
|
|
2083
|
-
return _timesToRepeat => repeat(x, _timesToRepeat);
|
|
2084
|
-
}
|
|
2085
|
-
|
|
2086
|
-
return Array(timesToRepeat).fill(x);
|
|
2087
|
-
}
|
|
2088
|
-
|
|
2089
|
-
function replaceFn(pattern, replacer, str) {
|
|
2090
|
-
return str.replace(pattern, replacer);
|
|
2091
|
-
}
|
|
2092
|
-
|
|
2093
|
-
const replace = curry(replaceFn);
|
|
2094
|
-
|
|
2095
|
-
function reverse(listOrString) {
|
|
2096
|
-
if (typeof listOrString === 'string') {
|
|
2097
|
-
return listOrString.split('').reverse().join('');
|
|
2098
|
-
}
|
|
2099
|
-
|
|
2100
|
-
const clone = listOrString.slice();
|
|
2101
|
-
return clone.reverse();
|
|
2102
|
-
}
|
|
2103
|
-
|
|
2104
|
-
function setFn(lens, replacer, x) {
|
|
2105
|
-
return over(lens, always(replacer), x);
|
|
2106
|
-
}
|
|
2107
|
-
|
|
2108
|
-
const set = curry(setFn);
|
|
2109
|
-
|
|
2110
|
-
function sliceFn(from, to, list) {
|
|
2111
|
-
return list.slice(from, to);
|
|
2112
|
-
}
|
|
2113
|
-
|
|
2114
|
-
const slice = curry(sliceFn);
|
|
2115
|
-
|
|
2116
|
-
function sort(sortFn, list) {
|
|
2117
|
-
if (arguments.length === 1) return _list => sort(sortFn, _list);
|
|
2118
|
-
return cloneList(list).sort(sortFn);
|
|
2119
|
-
}
|
|
2120
|
-
|
|
2121
|
-
function sortBy(sortFn, list) {
|
|
2122
|
-
if (arguments.length === 1) return _list => sortBy(sortFn, _list);
|
|
2123
|
-
const clone = cloneList(list);
|
|
2124
|
-
return clone.sort((a, b) => {
|
|
2125
|
-
const aSortResult = sortFn(a);
|
|
2126
|
-
const bSortResult = sortFn(b);
|
|
2127
|
-
if (aSortResult === bSortResult) return 0;
|
|
2128
|
-
return aSortResult < bSortResult ? -1 : 1;
|
|
2129
|
-
});
|
|
2130
|
-
}
|
|
2131
|
-
|
|
2132
|
-
function split(separator, str) {
|
|
2133
|
-
if (arguments.length === 1) return _str => split(separator, _str);
|
|
2134
|
-
return str.split(separator);
|
|
2135
|
-
}
|
|
2136
|
-
|
|
2137
|
-
function maybe(ifRule, whenIf, whenElse) {
|
|
2138
|
-
const whenIfInput = ifRule && type(whenIf) === 'Function' ? whenIf() : whenIf;
|
|
2139
|
-
const whenElseInput = !ifRule && type(whenElse) === 'Function' ? whenElse() : whenElse;
|
|
2140
|
-
return ifRule ? whenIfInput : whenElseInput;
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
function take(howMany, listOrString) {
|
|
2144
|
-
if (arguments.length === 1) return _listOrString => take(howMany, _listOrString);
|
|
2145
|
-
if (howMany < 0) return listOrString.slice();
|
|
2146
|
-
if (typeof listOrString === 'string') return listOrString.slice(0, howMany);
|
|
2147
|
-
return baseSlice(listOrString, 0, howMany);
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
|
-
function splitAt(index, input) {
|
|
2151
|
-
if (arguments.length === 1) {
|
|
2152
|
-
return _list => splitAt(index, _list);
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
if (!input) throw new TypeError(`Cannot read property 'slice' of ${input}`);
|
|
2156
|
-
if (!isArray(input) && typeof input !== 'string') return [[], []];
|
|
2157
|
-
const correctIndex = maybe(index < 0, input.length + index < 0 ? 0 : input.length + index, index);
|
|
2158
|
-
return [take(correctIndex, input), drop(correctIndex, input)];
|
|
2159
|
-
}
|
|
2160
|
-
|
|
2161
|
-
function splitEvery(sliceLength, listOrString) {
|
|
2162
|
-
if (arguments.length === 1) {
|
|
2163
|
-
return _listOrString => splitEvery(sliceLength, _listOrString);
|
|
2164
|
-
}
|
|
2165
|
-
|
|
2166
|
-
if (sliceLength < 1) {
|
|
2167
|
-
throw new Error('First argument to splitEvery must be a positive integer');
|
|
2168
|
-
}
|
|
2169
|
-
|
|
2170
|
-
const willReturn = [];
|
|
2171
|
-
let counter = 0;
|
|
2172
|
-
|
|
2173
|
-
while (counter < listOrString.length) {
|
|
2174
|
-
willReturn.push(listOrString.slice(counter, counter += sliceLength));
|
|
2175
|
-
}
|
|
2176
|
-
|
|
2177
|
-
return willReturn;
|
|
2178
|
-
}
|
|
2179
|
-
|
|
2180
|
-
function splitWhen(predicate, input) {
|
|
2181
|
-
if (arguments.length === 1) {
|
|
2182
|
-
return _input => splitWhen(predicate, _input);
|
|
2183
|
-
}
|
|
2184
|
-
|
|
2185
|
-
if (!input) throw new TypeError(`Cannot read property 'length' of ${input}`);
|
|
2186
|
-
const preFound = [];
|
|
2187
|
-
const postFound = [];
|
|
2188
|
-
let found = false;
|
|
2189
|
-
let counter = -1;
|
|
2190
|
-
|
|
2191
|
-
while (counter++ < input.length - 1) {
|
|
2192
|
-
if (found) {
|
|
2193
|
-
postFound.push(input[counter]);
|
|
2194
|
-
} else if (predicate(input[counter])) {
|
|
2195
|
-
postFound.push(input[counter]);
|
|
2196
|
-
found = true;
|
|
2197
|
-
} else {
|
|
2198
|
-
preFound.push(input[counter]);
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
|
|
2202
|
-
return [preFound, postFound];
|
|
2203
|
-
}
|
|
2204
|
-
|
|
2205
|
-
function startsWith(target, iterable) {
|
|
2206
|
-
if (arguments.length === 1) return _iterable => startsWith(target, _iterable);
|
|
2207
|
-
|
|
2208
|
-
if (typeof iterable === 'string') {
|
|
2209
|
-
return iterable.startsWith(target);
|
|
2210
|
-
}
|
|
2211
|
-
|
|
2212
|
-
if (!isArray(target)) return false;
|
|
2213
|
-
let correct = true;
|
|
2214
|
-
const filtered = target.filter((x, index) => {
|
|
2215
|
-
if (!correct) return false;
|
|
2216
|
-
const result = equals(x, iterable[index]);
|
|
2217
|
-
if (!result) correct = false;
|
|
2218
|
-
return result;
|
|
2219
|
-
});
|
|
2220
|
-
return filtered.length === target.length;
|
|
2221
|
-
}
|
|
2222
|
-
|
|
2223
|
-
function subtract(a, b) {
|
|
2224
|
-
if (arguments.length === 1) return _b => subtract(a, _b);
|
|
2225
|
-
return a - b;
|
|
2226
|
-
}
|
|
2227
|
-
|
|
2228
|
-
function symmetricDifference(x, y) {
|
|
2229
|
-
if (arguments.length === 1) {
|
|
2230
|
-
return _y => symmetricDifference(x, _y);
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2233
|
-
return concat(filter(value => !includes(value, y), x), filter(value => !includes(value, x), y));
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2236
|
-
function tail(listOrString) {
|
|
2237
|
-
return drop(1, listOrString);
|
|
2238
|
-
}
|
|
2239
|
-
|
|
2240
|
-
function takeLast(howMany, listOrString) {
|
|
2241
|
-
if (arguments.length === 1) return _listOrString => takeLast(howMany, _listOrString);
|
|
2242
|
-
const len = listOrString.length;
|
|
2243
|
-
if (howMany < 0) return listOrString.slice();
|
|
2244
|
-
let numValue = howMany > len ? len : howMany;
|
|
2245
|
-
if (typeof listOrString === 'string') return listOrString.slice(len - numValue);
|
|
2246
|
-
numValue = len - numValue;
|
|
2247
|
-
return baseSlice(listOrString, numValue, len);
|
|
2248
|
-
}
|
|
2249
|
-
|
|
2250
|
-
function takeLastWhile(predicate, input) {
|
|
2251
|
-
if (arguments.length === 1) {
|
|
2252
|
-
return _input => takeLastWhile(predicate, _input);
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2255
|
-
if (input.length === 0) return input;
|
|
2256
|
-
let found = false;
|
|
2257
|
-
const toReturn = [];
|
|
2258
|
-
let counter = input.length;
|
|
2259
|
-
|
|
2260
|
-
while (!found || counter === 0) {
|
|
2261
|
-
counter--;
|
|
2262
|
-
|
|
2263
|
-
if (predicate(input[counter]) === false) {
|
|
2264
|
-
found = true;
|
|
2265
|
-
} else if (!found) {
|
|
2266
|
-
toReturn.push(input[counter]);
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
|
|
2270
|
-
return isArray(input) ? toReturn.reverse() : toReturn.reverse().join('');
|
|
2271
|
-
}
|
|
2272
|
-
|
|
2273
|
-
function takeWhile(predicate, iterable) {
|
|
2274
|
-
if (arguments.length === 1) {
|
|
2275
|
-
return _iterable => takeWhile(predicate, _iterable);
|
|
2276
|
-
}
|
|
2277
|
-
|
|
2278
|
-
const isArray$1 = isArray(iterable);
|
|
2279
|
-
|
|
2280
|
-
if (!isArray$1 && typeof iterable !== 'string') {
|
|
2281
|
-
throw new Error('`iterable` is neither list nor a string');
|
|
2282
|
-
}
|
|
2283
|
-
|
|
2284
|
-
let flag = true;
|
|
2285
|
-
const holder = [];
|
|
2286
|
-
let counter = -1;
|
|
2287
|
-
|
|
2288
|
-
while (counter++ < iterable.length - 1) {
|
|
2289
|
-
if (!predicate(iterable[counter])) {
|
|
2290
|
-
if (flag) flag = false;
|
|
2291
|
-
} else if (flag) {
|
|
2292
|
-
holder.push(iterable[counter]);
|
|
2293
|
-
}
|
|
2294
|
-
}
|
|
2295
|
-
return isArray$1 ? holder : holder.join('');
|
|
2296
|
-
}
|
|
2297
|
-
|
|
2298
|
-
function tap(fn, x) {
|
|
2299
|
-
if (arguments.length === 1) return _x => tap(fn, _x);
|
|
2300
|
-
fn(x);
|
|
2301
|
-
return x;
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
|
-
function test(pattern, str) {
|
|
2305
|
-
if (arguments.length === 1) return _str => test(pattern, _str);
|
|
2306
|
-
|
|
2307
|
-
if (typeof pattern === 'string') {
|
|
2308
|
-
throw new TypeError(`‘test’ requires a value of type RegExp as its first argument; received "${pattern}"`);
|
|
2309
|
-
}
|
|
2310
|
-
|
|
2311
|
-
return str.search(pattern) !== -1;
|
|
2312
|
-
}
|
|
2313
|
-
|
|
2314
|
-
function times(fn, howMany) {
|
|
2315
|
-
if (arguments.length === 1) return _howMany => times(fn, _howMany);
|
|
2316
|
-
|
|
2317
|
-
if (!isInteger(howMany) || howMany < 0) {
|
|
2318
|
-
throw new RangeError('n must be an integer');
|
|
2319
|
-
}
|
|
2320
|
-
|
|
2321
|
-
return map(fn, range(0, howMany));
|
|
2322
|
-
}
|
|
2323
|
-
|
|
2324
|
-
function toLower(str) {
|
|
2325
|
-
return str.toLowerCase();
|
|
2326
|
-
}
|
|
2327
|
-
|
|
2328
|
-
function toPairs(obj) {
|
|
2329
|
-
return Object.entries(obj);
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
function toString(x) {
|
|
2333
|
-
return x.toString();
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
function toUpper(str) {
|
|
2337
|
-
return str.toUpperCase();
|
|
2338
|
-
}
|
|
2339
|
-
|
|
2340
|
-
function transpose(array) {
|
|
2341
|
-
return array.reduce((acc, el) => {
|
|
2342
|
-
el.forEach((nestedEl, i) => isArray(acc[i]) ? acc[i].push(nestedEl) : acc.push([nestedEl]));
|
|
2343
|
-
return acc;
|
|
2344
|
-
}, []);
|
|
2345
|
-
}
|
|
2346
|
-
|
|
2347
|
-
function trim(str) {
|
|
2348
|
-
return str.trim();
|
|
2349
|
-
}
|
|
2350
|
-
|
|
2351
|
-
const isFunction = x => ['Promise', 'Function'].includes(type(x));
|
|
2352
|
-
|
|
2353
|
-
function tryCatch(fn, fallback) {
|
|
2354
|
-
if (!isFunction(fn)) {
|
|
2355
|
-
throw new Error(`R.tryCatch | fn '${fn}'`);
|
|
2356
|
-
}
|
|
2357
|
-
|
|
2358
|
-
const passFallback = isFunction(fallback);
|
|
2359
|
-
return (...inputs) => {
|
|
2360
|
-
try {
|
|
2361
|
-
return fn(...inputs);
|
|
2362
|
-
} catch (e) {
|
|
2363
|
-
return passFallback ? fallback(e, ...inputs) : fallback;
|
|
2364
|
-
}
|
|
2365
|
-
};
|
|
2366
|
-
}
|
|
2367
|
-
|
|
2368
|
-
function unapply(fn) {
|
|
2369
|
-
return function (...args) {
|
|
2370
|
-
return fn.call(this, args);
|
|
2371
|
-
};
|
|
2372
|
-
}
|
|
2373
|
-
|
|
2374
|
-
function union(x, y) {
|
|
2375
|
-
if (arguments.length === 1) return _y => union(x, _y);
|
|
2376
|
-
const toReturn = cloneList(x);
|
|
2377
|
-
y.forEach(yInstance => {
|
|
2378
|
-
if (!includes(yInstance, x)) toReturn.push(yInstance);
|
|
2379
|
-
});
|
|
2380
|
-
return toReturn;
|
|
2381
|
-
}
|
|
2382
|
-
|
|
2383
|
-
function uniqBy(fn, list) {
|
|
2384
|
-
if (arguments.length === 1) {
|
|
2385
|
-
return _list => uniqBy(fn, _list);
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
|
-
const set = new Set();
|
|
2389
|
-
return list.filter(item => {
|
|
2390
|
-
if (set.has(fn(item))) return false;
|
|
2391
|
-
set.add(fn(item));
|
|
2392
|
-
return true;
|
|
2393
|
-
});
|
|
2394
|
-
}
|
|
2395
|
-
|
|
2396
|
-
function includesWith(predicate, target, list) {
|
|
2397
|
-
let willReturn = false;
|
|
2398
|
-
let index = -1;
|
|
2399
|
-
|
|
2400
|
-
while (++index < list.length && !willReturn) {
|
|
2401
|
-
const value = list[index];
|
|
2402
|
-
|
|
2403
|
-
if (predicate(target, value)) {
|
|
2404
|
-
willReturn = true;
|
|
2405
|
-
}
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
|
-
return willReturn;
|
|
2409
|
-
}
|
|
2410
|
-
|
|
2411
|
-
function uniqWith(predicate, list) {
|
|
2412
|
-
if (arguments.length === 1) return _list => uniqWith(predicate, _list);
|
|
2413
|
-
let index = -1;
|
|
2414
|
-
const willReturn = [];
|
|
2415
|
-
|
|
2416
|
-
while (++index < list.length) {
|
|
2417
|
-
const value = list[index];
|
|
2418
|
-
|
|
2419
|
-
if (!includesWith(predicate, value, willReturn)) {
|
|
2420
|
-
willReturn.push(value);
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
|
|
2424
|
-
return willReturn;
|
|
2425
|
-
}
|
|
2426
|
-
|
|
2427
|
-
function unless(predicate, whenFalse) {
|
|
2428
|
-
if (arguments.length === 1) {
|
|
2429
|
-
return _whenFalse => unless(predicate, _whenFalse);
|
|
2430
|
-
}
|
|
2431
|
-
|
|
2432
|
-
return input => predicate(input) ? input : whenFalse(input);
|
|
2433
|
-
}
|
|
2434
|
-
|
|
2435
|
-
function unwind(property, obj) {
|
|
2436
|
-
if (arguments.length === 1) {
|
|
2437
|
-
return _obj => unwind(property, _obj);
|
|
2438
|
-
}
|
|
2439
|
-
|
|
2440
|
-
if (!isArray(obj[property])) return [obj];
|
|
2441
|
-
return mapArray(x => _objectSpread2(_objectSpread2({}, obj), {}, {
|
|
2442
|
-
[property]: x
|
|
2443
|
-
}), obj[property]);
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
|
-
function values(obj) {
|
|
2447
|
-
if (type(obj) !== 'Object') return [];
|
|
2448
|
-
return Object.values(obj);
|
|
2449
|
-
}
|
|
2450
|
-
|
|
2451
|
-
const Const = x => ({
|
|
2452
|
-
x,
|
|
2453
|
-
map: fn => Const(x)
|
|
2454
|
-
});
|
|
2455
|
-
|
|
2456
|
-
function view(lens, target) {
|
|
2457
|
-
if (arguments.length === 1) return _target => view(lens, _target);
|
|
2458
|
-
return lens(Const)(target).x;
|
|
2459
|
-
}
|
|
2460
|
-
|
|
2461
|
-
function whenFn(predicate, whenTrueFn, input) {
|
|
2462
|
-
if (!predicate(input)) return input;
|
|
2463
|
-
return whenTrueFn(input);
|
|
2464
|
-
}
|
|
2465
|
-
|
|
2466
|
-
const when = curry(whenFn);
|
|
2467
|
-
|
|
2468
|
-
function where(conditions, input) {
|
|
2469
|
-
if (input === undefined) {
|
|
2470
|
-
return _input => where(conditions, _input);
|
|
2471
|
-
}
|
|
2472
|
-
|
|
2473
|
-
let flag = true;
|
|
2474
|
-
|
|
2475
|
-
for (const prop in conditions) {
|
|
2476
|
-
if (!flag) continue;
|
|
2477
|
-
const result = conditions[prop](input[prop]);
|
|
2478
|
-
|
|
2479
|
-
if (flag && result === false) {
|
|
2480
|
-
flag = false;
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
|
|
2484
|
-
return flag;
|
|
2485
|
-
}
|
|
2486
|
-
|
|
2487
|
-
function whereAny(conditions, input) {
|
|
2488
|
-
if (input === undefined) {
|
|
2489
|
-
return _input => whereAny(conditions, _input);
|
|
2490
|
-
}
|
|
2491
|
-
|
|
2492
|
-
for (const prop in conditions) {
|
|
2493
|
-
if (conditions[prop](input[prop])) {
|
|
2494
|
-
return true;
|
|
2495
|
-
}
|
|
2496
|
-
}
|
|
2497
|
-
|
|
2498
|
-
return false;
|
|
2499
|
-
}
|
|
2500
|
-
|
|
2501
|
-
function whereEq(condition, input) {
|
|
2502
|
-
if (arguments.length === 1) {
|
|
2503
|
-
return _input => whereEq(condition, _input);
|
|
2504
|
-
}
|
|
2505
|
-
|
|
2506
|
-
const result = filter((conditionValue, conditionProp) => equals(conditionValue, input[conditionProp]), condition);
|
|
2507
|
-
return Object.keys(result).length === Object.keys(condition).length;
|
|
2508
|
-
}
|
|
2509
|
-
|
|
2510
|
-
function without(matchAgainst, source) {
|
|
2511
|
-
if (source === undefined) {
|
|
2512
|
-
return _source => without(matchAgainst, _source);
|
|
2513
|
-
}
|
|
2514
|
-
|
|
2515
|
-
return reduce((prev, current) => _indexOf(current, matchAgainst) > -1 ? prev : prev.concat(current), [], source);
|
|
2516
|
-
}
|
|
2517
|
-
|
|
2518
|
-
function xor(a, b) {
|
|
2519
|
-
if (arguments.length === 1) return _b => xor(a, _b);
|
|
2520
|
-
return Boolean(a) && !b || Boolean(b) && !a;
|
|
2521
|
-
}
|
|
2522
|
-
|
|
2523
|
-
function zip(left, right) {
|
|
2524
|
-
if (arguments.length === 1) return _right => zip(left, _right);
|
|
2525
|
-
const result = [];
|
|
2526
|
-
const length = Math.min(left.length, right.length);
|
|
2527
|
-
|
|
2528
|
-
for (let i = 0; i < length; i++) {
|
|
2529
|
-
result[i] = [left[i], right[i]];
|
|
2530
|
-
}
|
|
2531
|
-
|
|
2532
|
-
return result;
|
|
2533
|
-
}
|
|
2534
|
-
|
|
2535
|
-
function zipObj(keys, values) {
|
|
2536
|
-
if (arguments.length === 1) return yHolder => zipObj(keys, yHolder);
|
|
2537
|
-
return take(values.length, keys).reduce((prev, xInstance, i) => {
|
|
2538
|
-
prev[xInstance] = values[i];
|
|
2539
|
-
return prev;
|
|
2540
|
-
}, {});
|
|
2541
|
-
}
|
|
2542
|
-
|
|
2543
|
-
function zipWithFn(fn, x, y) {
|
|
2544
|
-
return take(x.length > y.length ? y.length : x.length, x).map((xInstance, i) => fn(xInstance, y[i]));
|
|
2545
|
-
}
|
|
2546
|
-
|
|
2547
|
-
const zipWith = curry(zipWithFn);
|
|
2548
|
-
|
|
2549
|
-
export { F, T, __findHighestArity, _arity, _indexOf, _lastIndexOf, _pipe, add, adjust, all, allPass, always, and, any, anyPass, append, apply, applySpec, assoc, assocPath, bind, both, chain, clamp, clone, complement, compose, concat, cond, converge, count, countBy, curry, curryN, dec, defaultTo, difference, dissoc, divide, drop, dropLast, dropLastWhile, dropRepeats, dropRepeatsWith, dropWhile, either, endsWith, eqProps, equals, evolve, evolveArray, evolveObject, filter, filterArray, filterObject, find, findIndex, findLast, findLastIndex, flatten, flip, forEach, fromPairs, groupBy, groupWith, has, hasPath, head, identical, identity, ifElse, inc, includes, indexBy, indexOf, init, intersection, intersperse, is, isEmpty, isNil, join, juxt, keys, last, lastIndexOf, length, lens, lensIndex, lensPath, lensProp, map, mapArray, mapObjIndexed, mapObject, match, mathMod, max, maxBy, maxByFn, mean, median, mergeRight as merge, mergeAll, mergeDeepRight, mergeLeft, mergeRight, mergeWith, min, minBy, minByFn, modify, modifyPath, modifyPathFn, modulo, move, multiply, negate, none, not, nth, objOf, of, omit, on, once, or, over, partial, partialObject, partition, partitionArray, partitionObject, path, pathEq, pathOr, paths, pick, pickAll, pipe, pluck, prepend, product, prop, propEq, propIs, propOr, propSatisfies, props, range, reduce, reduceFn, reduceStopper, reject, repeat, replace, reverse, set, slice, sort, sortBy, split, splitAt, splitEvery, splitWhen, startsWith, subtract, sum, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile, tap, test, times, toLower, toPairs, toString, toUpper, transpose, trim, tryCatch, type, unapply, union, uniq, uniqBy, uniqWith, unless, unwind, update, updateFn, values, view, when, where, whereAny, whereEq, without, xor, zip, zipObj, zipWith };
|