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