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