occam-languages 2.2.63 → 3.0.2
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/lib/utilities/continuation.js +190 -285
- package/package.json +1 -1
- package/src/utilities/continuation.js +191 -344
|
@@ -4,401 +4,301 @@ import { arrayUtilities } from "necessary";
|
|
|
4
4
|
|
|
5
5
|
const { filter: arrayFilter } = arrayUtilities;
|
|
6
6
|
|
|
7
|
-
export function
|
|
7
|
+
export function one(array, callback, ...initialArguments) {
|
|
8
8
|
const continuation = initialArguments.pop(),
|
|
9
|
-
length = array.length
|
|
10
|
-
|
|
11
|
-
let count = 0,
|
|
12
|
-
index = -1;
|
|
13
|
-
|
|
14
|
-
let finalArguments;
|
|
15
|
-
|
|
16
|
-
function next(...callbackArguments) {
|
|
17
|
-
index++;
|
|
9
|
+
length = array.length,
|
|
10
|
+
index = 0;
|
|
18
11
|
|
|
12
|
+
function next(index, ...nextArguments) {
|
|
19
13
|
if (index === length) {
|
|
20
|
-
const success = (count === 1)
|
|
14
|
+
const success = (count === 1),
|
|
15
|
+
finalArguemnts = success ?
|
|
16
|
+
nextArguments : ///
|
|
17
|
+
initialArguments; ///
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
finalArguments = initialArguments; ///
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return continuation(success, ...finalArguments);
|
|
19
|
+
return continuation(success, ...finalArguemnts);
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
const element = array[index];
|
|
30
23
|
|
|
31
|
-
return callback(element, ...
|
|
24
|
+
return callback(element, ...initialArguments, (success, ...callbackArguments) => {
|
|
32
25
|
if (success) {
|
|
33
|
-
|
|
34
|
-
const success = false;
|
|
26
|
+
count++;
|
|
35
27
|
|
|
36
|
-
|
|
28
|
+
if (count === 2) {
|
|
29
|
+
const success = false,
|
|
30
|
+
finalArguments = initialArguments; ///
|
|
37
31
|
|
|
38
32
|
return continuation(success, ...finalArguments);
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
count++;
|
|
35
|
+
return next(index + 1, ...callbackArguments);
|
|
44
36
|
}
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return next(...callbackArguments);
|
|
38
|
+
return next(index + 1, ...nextArguments);
|
|
49
39
|
});
|
|
50
40
|
}
|
|
51
41
|
|
|
52
|
-
|
|
42
|
+
let count = 0;
|
|
53
43
|
|
|
54
|
-
return next(...
|
|
44
|
+
return next(index, ...initialArguments);
|
|
55
45
|
}
|
|
56
46
|
|
|
57
|
-
export function
|
|
47
|
+
export function some(array, callback, ...initialArguments) {
|
|
58
48
|
const continuation = initialArguments.pop(),
|
|
59
|
-
length = array.length
|
|
60
|
-
|
|
61
|
-
let index = -1;
|
|
62
|
-
|
|
63
|
-
let finalArguments;
|
|
64
|
-
|
|
65
|
-
function next(...callbackArguments) {
|
|
66
|
-
index++;
|
|
49
|
+
length = array.length,
|
|
50
|
+
index = 0;
|
|
67
51
|
|
|
52
|
+
function next(index) {
|
|
68
53
|
if (index === length) {
|
|
69
|
-
const success = false
|
|
70
|
-
|
|
71
|
-
finalArguments = initialArguments; ///
|
|
54
|
+
const success = false,
|
|
55
|
+
finalArguments = initialArguments; ///
|
|
72
56
|
|
|
73
57
|
return continuation(success, ...finalArguments);
|
|
74
58
|
}
|
|
75
59
|
|
|
76
60
|
const element = array[index];
|
|
77
61
|
|
|
78
|
-
return callback(element, ...
|
|
62
|
+
return callback(element, ...initialArguments, (success, ...callbackArguments) => {
|
|
79
63
|
if (success) {
|
|
80
|
-
finalArguments =
|
|
64
|
+
const finalArguments = callbackArguments; //
|
|
81
65
|
|
|
82
66
|
return continuation(success, ...finalArguments);
|
|
83
67
|
}
|
|
84
68
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return next(...callbackArguments);
|
|
69
|
+
return next(index + 1);
|
|
88
70
|
});
|
|
89
71
|
}
|
|
90
72
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return next(...callbackArguments);
|
|
73
|
+
return next(index);
|
|
94
74
|
}
|
|
95
75
|
|
|
96
|
-
export function
|
|
76
|
+
export function each(array, callback, ...initialArguments) {
|
|
97
77
|
const continuation = initialArguments.pop(),
|
|
98
|
-
length = array.length
|
|
99
|
-
|
|
100
|
-
let count = 0,
|
|
101
|
-
index = -1;
|
|
102
|
-
|
|
103
|
-
let finalArguments;
|
|
104
|
-
|
|
105
|
-
function next(...callbackArguments) {
|
|
106
|
-
index++;
|
|
78
|
+
length = array.length,
|
|
79
|
+
index = 0;
|
|
107
80
|
|
|
81
|
+
function next(index, ...nextArguments) {
|
|
108
82
|
if (index === length) {
|
|
109
|
-
const success = (count
|
|
110
|
-
|
|
111
|
-
|
|
83
|
+
const success = (count !== 0),
|
|
84
|
+
finalArguments = success ?
|
|
85
|
+
nextArguments : ///
|
|
86
|
+
initialArguments; ///
|
|
112
87
|
|
|
113
88
|
return continuation(success, ...finalArguments);
|
|
114
89
|
}
|
|
115
90
|
|
|
116
91
|
const element = array[index];
|
|
117
92
|
|
|
118
|
-
return callback(element, ...
|
|
93
|
+
return callback(element, ...nextArguments, (success, ...callbackArguments) => {
|
|
119
94
|
if (!success) {
|
|
120
|
-
finalArguments = initialArguments;
|
|
95
|
+
const finalArguments = initialArguments; ///
|
|
121
96
|
|
|
122
97
|
return continuation(success, ...finalArguments);
|
|
123
98
|
}
|
|
124
99
|
|
|
125
100
|
count++;
|
|
126
101
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return next(...callbackArguments);
|
|
102
|
+
return next(index + 1, ...callbackArguments);
|
|
130
103
|
});
|
|
131
104
|
}
|
|
132
105
|
|
|
133
|
-
|
|
106
|
+
let count = 0;
|
|
134
107
|
|
|
135
|
-
return next(...
|
|
108
|
+
return next(index, ...initialArguments);
|
|
136
109
|
}
|
|
137
110
|
|
|
138
|
-
export function
|
|
111
|
+
export function every(array, callback, ...initialArguments) {
|
|
139
112
|
const continuation = initialArguments.pop(),
|
|
140
|
-
length = array.length
|
|
141
|
-
|
|
142
|
-
let index = -1;
|
|
143
|
-
|
|
144
|
-
let finalArguments;
|
|
145
|
-
|
|
146
|
-
function next(...callbackArguments) {
|
|
147
|
-
index++;
|
|
113
|
+
length = array.length,
|
|
114
|
+
index = 0;
|
|
148
115
|
|
|
116
|
+
function next(index, ...nextArguments) {
|
|
149
117
|
if (index === length) {
|
|
150
|
-
const success = true
|
|
151
|
-
|
|
152
|
-
finalArguments = callbackArguments; ///
|
|
118
|
+
const success = true,
|
|
119
|
+
finalArguments = nextArguments; ///
|
|
153
120
|
|
|
154
121
|
return continuation(success, ...finalArguments);
|
|
155
122
|
}
|
|
156
123
|
|
|
157
124
|
const element = array[index];
|
|
158
125
|
|
|
159
|
-
return callback(element, ...
|
|
126
|
+
return callback(element, ...nextArguments, (success, ...callbackArguments) => {
|
|
160
127
|
if (!success) {
|
|
161
|
-
finalArguments = initialArguments;
|
|
128
|
+
const finalArguments = initialArguments; ///
|
|
162
129
|
|
|
163
130
|
return continuation(success, ...finalArguments);
|
|
164
131
|
}
|
|
165
132
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return next(...callbackArguments);
|
|
133
|
+
return next(index + 1, ...callbackArguments);
|
|
169
134
|
});
|
|
170
135
|
}
|
|
171
136
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return next(...callbackArguments);
|
|
137
|
+
return next(index, ...initialArguments);
|
|
175
138
|
}
|
|
176
139
|
|
|
177
|
-
export function
|
|
140
|
+
export function reduce(array, initialValue, callback, ...initialArguments) {
|
|
178
141
|
const continuation = initialArguments.pop(),
|
|
179
|
-
length = array.length
|
|
180
|
-
|
|
181
|
-
let index = -1;
|
|
182
|
-
|
|
183
|
-
let finalArguments;
|
|
184
|
-
|
|
185
|
-
function next(value, ...callbackArguments) {
|
|
186
|
-
index++;
|
|
142
|
+
length = array.length,
|
|
143
|
+
index = 0;
|
|
187
144
|
|
|
145
|
+
function next(index, value, ...nextArguments) {
|
|
188
146
|
if (index === length) {
|
|
189
|
-
finalArguments =
|
|
147
|
+
const finalArguments = nextArguments; ///
|
|
190
148
|
|
|
191
149
|
return continuation(value, ...finalArguments);
|
|
192
150
|
}
|
|
193
151
|
|
|
194
152
|
const element = array[index];
|
|
195
153
|
|
|
196
|
-
return callback(element, value, ...
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return next(value, ...callbackArguments);
|
|
154
|
+
return callback(element, value, ...nextArguments, (value, ...callbackArguments) => {
|
|
155
|
+
return next(index + 1, value, ...callbackArguments);
|
|
200
156
|
});
|
|
201
157
|
}
|
|
202
158
|
|
|
203
|
-
|
|
204
|
-
callbackArguments = initialArguments; ///
|
|
205
|
-
|
|
206
|
-
return next(value, ...callbackArguments);
|
|
159
|
+
return next(index, initialValue, ...initialArguments);
|
|
207
160
|
}
|
|
208
161
|
|
|
209
|
-
export function
|
|
162
|
+
export function forEach(array, callback, ...initialArguments) {
|
|
210
163
|
const continuation = initialArguments.pop(),
|
|
211
|
-
length = array.length
|
|
212
|
-
|
|
213
|
-
let index = -1;
|
|
214
|
-
|
|
215
|
-
let finalArguments;
|
|
216
|
-
|
|
217
|
-
function next(...callbackArguments) {
|
|
218
|
-
index++;
|
|
164
|
+
length = array.length,
|
|
165
|
+
index = 0;
|
|
219
166
|
|
|
167
|
+
function next(index, ...nextArguments) {
|
|
220
168
|
if (index === length) {
|
|
221
|
-
finalArguments =
|
|
169
|
+
const finalArguments = nextArguments; ///
|
|
222
170
|
|
|
223
171
|
return continuation(...finalArguments);
|
|
224
172
|
}
|
|
225
173
|
|
|
226
174
|
const element = array[index];
|
|
227
175
|
|
|
228
|
-
return callback(element, ...
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return next(...callbackArguments);
|
|
176
|
+
return callback(element, ...nextArguments, (...callbackArguments) => {
|
|
177
|
+
return next(index + 1, ...callbackArguments);
|
|
232
178
|
});
|
|
233
179
|
}
|
|
234
180
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return next(...callbackArguments);
|
|
181
|
+
return next(index, ...initialArguments);
|
|
238
182
|
}
|
|
239
183
|
|
|
240
|
-
export function
|
|
184
|
+
export function forwardsEvery(array, callback, ...initialArguments) {
|
|
241
185
|
const continuation = initialArguments.pop(),
|
|
242
|
-
length = array.length
|
|
243
|
-
|
|
244
|
-
let index = -1;
|
|
245
|
-
|
|
246
|
-
let finalArguments;
|
|
247
|
-
|
|
248
|
-
function next(...callbackArguments) {
|
|
249
|
-
index++;
|
|
186
|
+
length = array.length,
|
|
187
|
+
index = 0;
|
|
250
188
|
|
|
189
|
+
function next(index, ...nextArguments) {
|
|
251
190
|
if (index === length) {
|
|
252
|
-
const success = true
|
|
253
|
-
|
|
254
|
-
finalArguments = callbackArguments; ///
|
|
191
|
+
const success = true,
|
|
192
|
+
finalArguments = nextArguments; ///
|
|
255
193
|
|
|
256
194
|
return continuation(success, ...finalArguments);
|
|
257
195
|
}
|
|
258
196
|
|
|
259
197
|
const element = array[index];
|
|
260
198
|
|
|
261
|
-
return callback(element, ...
|
|
199
|
+
return callback(element, ...nextArguments, (success, ...callbackArguments) => {
|
|
262
200
|
if (!success) {
|
|
263
|
-
finalArguments = initialArguments;
|
|
201
|
+
const finalArguments = initialArguments; ///
|
|
264
202
|
|
|
265
203
|
return continuation(success, ...finalArguments);
|
|
266
204
|
}
|
|
267
205
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return next(...callbackArguments);
|
|
206
|
+
return next(index + 1, ...callbackArguments);
|
|
271
207
|
});
|
|
272
208
|
}
|
|
273
209
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return next(...callbackArguments);
|
|
210
|
+
return next(index, ...initialArguments);
|
|
277
211
|
}
|
|
278
212
|
|
|
279
|
-
export function
|
|
213
|
+
export function backwardsEvery(array, callback, ...initialArguments) {
|
|
280
214
|
const continuation = initialArguments.pop(),
|
|
281
|
-
length = array.length
|
|
282
|
-
|
|
283
|
-
let index = length;
|
|
284
|
-
|
|
285
|
-
let finalArguments;
|
|
286
|
-
|
|
287
|
-
function next(...callbackArguments) {
|
|
288
|
-
index--;
|
|
215
|
+
length = array.length,
|
|
216
|
+
index = length - 1;
|
|
289
217
|
|
|
218
|
+
function next(index, ...nextArguments) {
|
|
290
219
|
if (index === -1) {
|
|
291
|
-
const success = true
|
|
292
|
-
|
|
293
|
-
finalArguments = callbackArguments; ///
|
|
220
|
+
const success = true,
|
|
221
|
+
finalArguments = nextArguments; ///
|
|
294
222
|
|
|
295
223
|
return continuation(success, ...finalArguments);
|
|
296
224
|
}
|
|
297
225
|
|
|
298
226
|
const element = array[index];
|
|
299
227
|
|
|
300
|
-
return callback(element, ...
|
|
228
|
+
return callback(element, ...nextArguments, (success, ...callbackArguments) => {
|
|
301
229
|
if (!success) {
|
|
302
|
-
finalArguments = initialArguments;
|
|
230
|
+
const finalArguments = initialArguments; ///
|
|
303
231
|
|
|
304
232
|
return continuation(success, ...finalArguments);
|
|
305
233
|
}
|
|
306
234
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
return next(...callbackArguments);
|
|
235
|
+
return next(index - 1, ...callbackArguments);
|
|
310
236
|
});
|
|
311
237
|
}
|
|
312
238
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return next(...callbackArguments);
|
|
239
|
+
return next(index, ...initialArguments);
|
|
316
240
|
}
|
|
317
241
|
|
|
318
|
-
export function
|
|
242
|
+
export function forwardsForEach(array, callback, ...initialArguments) {
|
|
319
243
|
const continuation = initialArguments.pop(),
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
let index = -1;
|
|
323
|
-
|
|
324
|
-
let finalArguments;
|
|
325
|
-
|
|
326
|
-
function next(...callbackArguments) {
|
|
327
|
-
index++;
|
|
244
|
+
length = array.length,
|
|
245
|
+
index = 0;
|
|
328
246
|
|
|
247
|
+
function next(index, ...nextArguments) {
|
|
329
248
|
if (index === length) {
|
|
330
|
-
finalArguments =
|
|
249
|
+
const finalArguments = nextArguments; ///
|
|
331
250
|
|
|
332
251
|
return continuation(...finalArguments);
|
|
333
252
|
}
|
|
334
253
|
|
|
335
254
|
const element = array[index];
|
|
336
255
|
|
|
337
|
-
return callback(element, ...
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
return next(...callbackArguments);
|
|
256
|
+
return callback(element, ...nextArguments, (...callbackArguments) => {
|
|
257
|
+
return next(index + 1, ...callbackArguments);
|
|
341
258
|
});
|
|
342
259
|
}
|
|
343
260
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return next(...callbackArguments);
|
|
261
|
+
return next(index, ...initialArguments);
|
|
347
262
|
}
|
|
348
263
|
|
|
349
|
-
export function
|
|
264
|
+
export function backwardsForEach(array, callback, ...initialArguments) {
|
|
350
265
|
const continuation = initialArguments.pop(),
|
|
351
|
-
length = array.length
|
|
352
|
-
|
|
353
|
-
let index = length;
|
|
354
|
-
|
|
355
|
-
let finalArguments;
|
|
356
|
-
|
|
357
|
-
function next(...callbackArguments) {
|
|
358
|
-
index--;
|
|
266
|
+
length = array.length,
|
|
267
|
+
index = length - 1;
|
|
359
268
|
|
|
269
|
+
function next(index, ...nextArguments) {
|
|
360
270
|
if (index === -1) {
|
|
361
|
-
finalArguments =
|
|
271
|
+
const finalArguments = nextArguments; ///
|
|
362
272
|
|
|
363
273
|
return continuation(...finalArguments);
|
|
364
274
|
}
|
|
365
275
|
|
|
366
276
|
const element = array[index];
|
|
367
277
|
|
|
368
|
-
return callback(element, ...
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
return next(...callbackArguments);
|
|
278
|
+
return callback(element, ...nextArguments, (...callbackArguments) => {
|
|
279
|
+
return next(index - 1, ...callbackArguments);
|
|
372
280
|
});
|
|
373
281
|
}
|
|
374
282
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return next(...callbackArguments);
|
|
283
|
+
return next(index, ...initialArguments);
|
|
378
284
|
}
|
|
379
285
|
|
|
380
|
-
export function
|
|
286
|
+
export function filter(array, callback, ...initialArguments) {
|
|
381
287
|
const continuation = initialArguments.pop(),
|
|
382
|
-
length = array.length
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
let index = length;
|
|
387
|
-
|
|
388
|
-
let finalArguments;
|
|
389
|
-
|
|
390
|
-
function next(...callbackArguments) {
|
|
391
|
-
index--;
|
|
288
|
+
length = array.length,
|
|
289
|
+
deletedElements = [],
|
|
290
|
+
index = length - 1;
|
|
392
291
|
|
|
292
|
+
function next(index, ...nextArguments) {
|
|
393
293
|
if (index === -1) {
|
|
394
|
-
finalArguments =
|
|
294
|
+
const finalArguments = nextArguments; ///
|
|
395
295
|
|
|
396
296
|
return continuation(deletedElements, ...finalArguments);
|
|
397
297
|
}
|
|
398
298
|
|
|
399
299
|
const element = array[index];
|
|
400
300
|
|
|
401
|
-
return callback(element, ...
|
|
301
|
+
return callback(element, ...nextArguments, (passed, ...callbackArguments) => {
|
|
402
302
|
if (!passed) {
|
|
403
303
|
const startIndex = index, ///
|
|
404
304
|
deleteCount = 1,
|
|
@@ -409,138 +309,100 @@ export function asynchronousFilter(array, callback, ...initialArguments) {
|
|
|
409
309
|
deletedElements.unshift(deletedElement);
|
|
410
310
|
}
|
|
411
311
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
return next(...callbackArguments);
|
|
312
|
+
return next(index - 1, ...callbackArguments);
|
|
415
313
|
});
|
|
416
314
|
}
|
|
417
315
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
return next(...callbackArguments);
|
|
316
|
+
return next(index, ...initialArguments);
|
|
421
317
|
}
|
|
422
318
|
|
|
423
|
-
export function
|
|
319
|
+
export function prune(array, callback, ...initialArguments) {
|
|
424
320
|
const continuation = initialArguments.pop(),
|
|
425
|
-
length = array.length
|
|
426
|
-
|
|
427
|
-
let deletedElement;
|
|
428
|
-
|
|
429
|
-
let index = -1;
|
|
430
|
-
|
|
431
|
-
let finalArguments;
|
|
432
|
-
|
|
433
|
-
function next(...callbackArguments) {
|
|
434
|
-
index++;
|
|
321
|
+
length = array.length,
|
|
322
|
+
index = 0;
|
|
435
323
|
|
|
324
|
+
function next(index) {
|
|
436
325
|
if (index === length) {
|
|
437
|
-
deletedElement = undefined
|
|
438
|
-
|
|
439
|
-
finalArguments = initialArguments; ///
|
|
326
|
+
const deletedElement = undefined,
|
|
327
|
+
finalArguments = initialArguments; ///
|
|
440
328
|
|
|
441
329
|
return continuation(deletedElement, ...finalArguments);
|
|
442
330
|
}
|
|
443
331
|
|
|
444
332
|
const element = array[index];
|
|
445
333
|
|
|
446
|
-
return callback(element, ...
|
|
334
|
+
return callback(element, ...initialArguments, (passed, ...callbackArguments) => {
|
|
447
335
|
if (!passed) {
|
|
448
336
|
const startIndex = index, ///
|
|
449
337
|
deleteCount = 1,
|
|
450
|
-
deletedElement = element
|
|
338
|
+
deletedElement = element, ///
|
|
339
|
+
finalArguments = callbackArguments; ///
|
|
451
340
|
|
|
452
341
|
array.splice(startIndex, deleteCount);
|
|
453
342
|
|
|
454
|
-
finalArguments = intermediateArguments; ///
|
|
455
|
-
|
|
456
343
|
return continuation(deletedElement, ...finalArguments);
|
|
457
344
|
}
|
|
458
345
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
return next(...callbackArguments);
|
|
346
|
+
return next(index + 1);
|
|
462
347
|
});
|
|
463
348
|
}
|
|
464
349
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
return next(...callbackArguments);
|
|
350
|
+
return next(index);
|
|
468
351
|
}
|
|
469
352
|
|
|
470
|
-
export function
|
|
353
|
+
export function extract(array, callback, ...initialArguments) {
|
|
471
354
|
const continuation = initialArguments.pop(),
|
|
472
|
-
length = array.length
|
|
473
|
-
|
|
474
|
-
let deletedElement;
|
|
475
|
-
|
|
476
|
-
let index = -1;
|
|
477
|
-
|
|
478
|
-
let finalArguments;
|
|
479
|
-
|
|
480
|
-
function next(...callbackArguments) {
|
|
481
|
-
index++;
|
|
355
|
+
length = array.length,
|
|
356
|
+
index = 0;
|
|
482
357
|
|
|
358
|
+
function next(index) {
|
|
483
359
|
if (index === length) {
|
|
484
|
-
deletedElement = undefined
|
|
485
|
-
|
|
486
|
-
finalArguments = initialArguments; ///
|
|
360
|
+
const deletedElement = undefined,
|
|
361
|
+
finalArguments = initialArguments; ///
|
|
487
362
|
|
|
488
363
|
return continuation(deletedElement, ...finalArguments);
|
|
489
364
|
}
|
|
490
365
|
|
|
491
366
|
const element = array[index];
|
|
492
367
|
|
|
493
|
-
return callback(element, ...
|
|
368
|
+
return callback(element, ...initialArguments, (passed, ...callbackArguments) => {
|
|
494
369
|
if (passed) {
|
|
495
370
|
const startIndex = index, ///
|
|
496
371
|
deleteCount = 1,
|
|
497
|
-
deletedElement = element
|
|
372
|
+
deletedElement = element, ///
|
|
373
|
+
finalArguments = callbackArguments; ///
|
|
498
374
|
|
|
499
375
|
array.splice(startIndex, deleteCount);
|
|
500
376
|
|
|
501
|
-
finalArguments = intermediateArguments; ///
|
|
502
|
-
|
|
503
377
|
return continuation(deletedElement, ...finalArguments);
|
|
504
378
|
}
|
|
505
379
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
return next(...callbackArguments);
|
|
380
|
+
return next(index + 1);
|
|
509
381
|
});
|
|
510
382
|
}
|
|
511
383
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
return next(...callbackArguments);
|
|
384
|
+
return next(index);
|
|
515
385
|
}
|
|
516
386
|
|
|
517
|
-
export function
|
|
518
|
-
const continuation = initialArguments.pop()
|
|
519
|
-
|
|
520
|
-
const arrayALength = arrayA.length,
|
|
387
|
+
export function match(arrayA, arrayB, callback, ...initialArguments) {
|
|
388
|
+
const continuation = initialArguments.pop(),
|
|
389
|
+
arrayALength = arrayA.length,
|
|
521
390
|
arrayBLength = arrayB.length;
|
|
522
391
|
|
|
523
|
-
let finalArguments;
|
|
524
|
-
|
|
525
392
|
if (arrayALength !== arrayBLength) {
|
|
526
|
-
const success = false
|
|
527
|
-
|
|
528
|
-
finalArguments = initialArguments; ///
|
|
393
|
+
const success = false,
|
|
394
|
+
finalArguments = initialArguments; ///
|
|
529
395
|
|
|
530
396
|
return continuation(success, ...finalArguments);
|
|
531
397
|
}
|
|
532
398
|
|
|
533
|
-
const length = arrayALength
|
|
534
|
-
|
|
535
|
-
let index = -1;
|
|
536
|
-
|
|
537
|
-
function next(...callbackArguments) {
|
|
538
|
-
index++;
|
|
399
|
+
const length = arrayALength, ///
|
|
400
|
+
index = 0;
|
|
539
401
|
|
|
402
|
+
function next(index, ...nextArguments) {
|
|
540
403
|
if (index === length) {
|
|
541
|
-
const success = true
|
|
542
|
-
|
|
543
|
-
finalArguments = callbackArguments; ///
|
|
404
|
+
const success = true,
|
|
405
|
+
finalArguments = nextArguments; ///
|
|
544
406
|
|
|
545
407
|
return continuation(success, ...finalArguments);
|
|
546
408
|
}
|
|
@@ -548,55 +410,40 @@ export function asynchronousMatch(arrayA, arrayB, callback, ...initialArguments)
|
|
|
548
410
|
const elementA = arrayA[index],
|
|
549
411
|
elementB = arrayB[index];
|
|
550
412
|
|
|
551
|
-
return callback(elementA, elementB, ...
|
|
413
|
+
return callback(elementA, elementB, ...nextArguments, (success, ...callbackArguments) => {
|
|
552
414
|
if (!success) {
|
|
553
|
-
finalArguments = initialArguments;
|
|
415
|
+
const finalArguments = initialArguments; ///
|
|
554
416
|
|
|
555
417
|
return continuation(success, ...finalArguments);
|
|
556
418
|
}
|
|
557
419
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
return next(...callbackArguments);
|
|
420
|
+
return next(index + 1, ...callbackArguments);
|
|
561
421
|
});
|
|
562
422
|
}
|
|
563
423
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
return next(...callbackArguments);
|
|
424
|
+
return next(index, ...initialArguments);
|
|
567
425
|
}
|
|
568
426
|
|
|
569
|
-
export function
|
|
427
|
+
export function resolve(arrayA, arrayB, callback, ...initialArguments) {
|
|
570
428
|
arrayA = [ ///
|
|
571
429
|
...arrayA
|
|
572
430
|
];
|
|
573
431
|
|
|
574
432
|
const continuation = initialArguments.pop();
|
|
575
433
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
function nextPass(...callbackArguments) {
|
|
579
|
-
let success = false;
|
|
580
|
-
|
|
434
|
+
function nextPass(...nextArguments) {
|
|
581
435
|
const length = arrayA.length; ///
|
|
582
436
|
|
|
583
437
|
if (length === 0) {
|
|
584
|
-
success = true
|
|
585
|
-
|
|
586
|
-
finalArguments = callbackArguments; ///
|
|
438
|
+
const success = true,
|
|
439
|
+
finalArguments = nextArguments; ///
|
|
587
440
|
|
|
588
441
|
return continuation(success, ...finalArguments);
|
|
589
442
|
}
|
|
590
443
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
function nextElement(...callbackArguments) {
|
|
594
|
-
index++;
|
|
595
|
-
|
|
444
|
+
function nextElement(index, success, ...currentArguments) {
|
|
596
445
|
if (index === length) {
|
|
597
446
|
if (!success) {
|
|
598
|
-
success = false;
|
|
599
|
-
|
|
600
447
|
const finalArguments = initialArguments; ///
|
|
601
448
|
|
|
602
449
|
return continuation(success, ...finalArguments);
|
|
@@ -610,62 +457,62 @@ export function asynchronousResolve(arrayA, arrayB, callback, ...initialArgument
|
|
|
610
457
|
}
|
|
611
458
|
});
|
|
612
459
|
|
|
613
|
-
return nextPass(...
|
|
614
|
-
}
|
|
615
|
-
const elementA = arrayA[index];
|
|
460
|
+
return nextPass(...currentArguments);
|
|
461
|
+
}
|
|
616
462
|
|
|
617
|
-
|
|
618
|
-
if (passed) {
|
|
619
|
-
callbackArguments = intermediateArguments; ///
|
|
463
|
+
const elementA = arrayA[index];
|
|
620
464
|
|
|
621
|
-
|
|
465
|
+
return callback(elementA, ...currentArguments, (passed, ...callbackArguments) => {
|
|
466
|
+
if (passed) {
|
|
467
|
+
const elementB = elementA, ///
|
|
468
|
+
success = true;
|
|
622
469
|
|
|
623
|
-
|
|
470
|
+
arrayB.push(elementB);
|
|
624
471
|
|
|
625
|
-
|
|
626
|
-
|
|
472
|
+
return nextElement(index + 1, success, ...callbackArguments);
|
|
473
|
+
}
|
|
627
474
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
475
|
+
return nextElement(index + 1, success, ...currentArguments);
|
|
476
|
+
});
|
|
631
477
|
}
|
|
632
478
|
|
|
633
|
-
|
|
634
|
-
|
|
479
|
+
const index = 0,
|
|
480
|
+
success = false;
|
|
635
481
|
|
|
636
|
-
|
|
482
|
+
return nextElement(index, success, ...nextArguments);
|
|
483
|
+
}
|
|
637
484
|
|
|
638
|
-
return nextPass(...
|
|
485
|
+
return nextPass(...initialArguments);
|
|
639
486
|
}
|
|
640
487
|
|
|
641
|
-
export function
|
|
642
|
-
return
|
|
488
|
+
export function all(callbacks, ...initialArguments) {
|
|
489
|
+
return every(callbacks, (callback, ...callbackArguments) => {
|
|
643
490
|
return callback(...callbackArguments);
|
|
644
491
|
}, ...initialArguments);
|
|
645
492
|
}
|
|
646
493
|
|
|
647
|
-
export function
|
|
648
|
-
return
|
|
494
|
+
export function exists(callbacks, ...initialArguments) {
|
|
495
|
+
return some(callbacks, (callback, ...callbackArguments) => {
|
|
649
496
|
return callback(...callbackArguments);
|
|
650
497
|
}, ...initialArguments);
|
|
651
498
|
}
|
|
652
499
|
|
|
653
500
|
export default {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
501
|
+
one,
|
|
502
|
+
some,
|
|
503
|
+
each,
|
|
504
|
+
every,
|
|
505
|
+
reduce,
|
|
506
|
+
forEach,
|
|
507
|
+
forwardsEvery,
|
|
508
|
+
backwardsEvery,
|
|
509
|
+
forwardsForEach,
|
|
510
|
+
backwardsForEach,
|
|
511
|
+
filter,
|
|
512
|
+
prune,
|
|
513
|
+
extract,
|
|
514
|
+
match,
|
|
515
|
+
resolve,
|
|
516
|
+
all,
|
|
517
|
+
exists
|
|
671
518
|
};
|