@bodil/monkey-business 0.1.4 → 0.2.1
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/dist/index.d.ts +25 -6
- package/dist/index.js +174 -233
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +1 -1
- package/dist/index.test.js.map +1 -1
- package/package.json +24 -14
- package/src/index.test.ts +1 -1
- package/src/index.ts +233 -283
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Option } from "@bodil/opt";
|
|
2
2
|
import { type OrderFn } from "@bodil/core/order";
|
|
3
3
|
import type { Present } from "@bodil/core/types";
|
|
4
|
+
import "es-iterator-helpers/Iterator.concat/auto";
|
|
5
|
+
import "es-iterator-helpers/Iterator.zip/auto";
|
|
6
|
+
import "es-iterator-helpers/Iterator.zipKeyed/auto";
|
|
4
7
|
declare global {
|
|
8
|
+
/**
|
|
9
|
+
* Added methods on the {@link Object} global object.
|
|
10
|
+
*/
|
|
5
11
|
interface ObjectConstructor {
|
|
6
12
|
/**
|
|
7
13
|
* Checked key lookup. Returns {@link None} if a key isn't present.
|
|
@@ -15,9 +21,9 @@ declare global {
|
|
|
15
21
|
*/
|
|
16
22
|
mapEntries<A, B>(obj: Record<string, A>, fn: (entry: [key: string, value: A]) => [string, B]): Record<string, B>;
|
|
17
23
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Added methods on {@link Map}s.
|
|
26
|
+
*/
|
|
21
27
|
interface Map<K, V> {
|
|
22
28
|
/**
|
|
23
29
|
* If `key` exists in the map, return the value associated with it.
|
|
@@ -26,6 +32,9 @@ declare global {
|
|
|
26
32
|
*/
|
|
27
33
|
getOrSet(key: K, defaultValue: () => V): V;
|
|
28
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Added methods on {@link Array}s.
|
|
37
|
+
*/
|
|
29
38
|
interface Array<T> {
|
|
30
39
|
/**
|
|
31
40
|
* Insert `value` at `index` in the array.
|
|
@@ -80,6 +89,9 @@ declare global {
|
|
|
80
89
|
*/
|
|
81
90
|
get(index: number): Option<T>;
|
|
82
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Added methods on the {@link Iterator} global object.
|
|
94
|
+
*/
|
|
83
95
|
interface IteratorConstructor {
|
|
84
96
|
/**
|
|
85
97
|
* Construct an empty iterator.
|
|
@@ -87,22 +99,29 @@ declare global {
|
|
|
87
99
|
empty<T>(): IteratorObject<T>;
|
|
88
100
|
/**
|
|
89
101
|
* Sequence multiple iterators into a single one.
|
|
90
|
-
*
|
|
102
|
+
* @see https://github.com/tc39/proposal-iterator-sequencing
|
|
91
103
|
*/
|
|
92
104
|
concat<T>(...inputs: Array<Iterable<T>>): IteratorObject<T>;
|
|
105
|
+
/**
|
|
106
|
+
* @see https://github.com/tc39/proposal-joint-iteration
|
|
107
|
+
*/
|
|
108
|
+
zip<T>(inputs: Iterable<Iterable<T>>): IteratorObject<Array<T>>;
|
|
109
|
+
/**
|
|
110
|
+
* @see https://github.com/tc39/proposal-joint-iteration
|
|
111
|
+
*/
|
|
112
|
+
zipKeyed<T>(inputs: Record<string, Iterable<T>>): IteratorObject<Record<string, T>>;
|
|
93
113
|
}
|
|
94
114
|
interface IteratorObject<T, TReturn, TNext> {
|
|
95
115
|
/**
|
|
96
116
|
* Get the next value from the iterator, wrapped in an {@link Option}
|
|
97
117
|
* type. If the iterator has no more values, return {@link None}.
|
|
98
|
-
*
|
|
99
|
-
* This is the nicely utility typed version of {@link Iterator#next}.
|
|
100
118
|
*/
|
|
101
119
|
takeOne(): Option<T>;
|
|
102
120
|
/**
|
|
103
121
|
* Take items from the iterator only until the first time `predicate` returns false.
|
|
104
122
|
*/
|
|
105
123
|
takeWhile<S extends T>(predicate: (value: T, index: number) => value is S): IteratorObject<S, undefined>;
|
|
124
|
+
/** @ignore */
|
|
106
125
|
takeWhile(predicate: (value: T, index: number) => boolean): IteratorObject<T, undefined>;
|
|
107
126
|
/**
|
|
108
127
|
* Ignore all items matching `predicate` until the first item that
|
package/dist/index.js
CHANGED
|
@@ -3,252 +3,193 @@
|
|
|
3
3
|
import { None, Option, Some } from "@bodil/opt";
|
|
4
4
|
import { bisectHigh, bisectLow } from "@bodil/core/order";
|
|
5
5
|
import { assert } from "@bodil/core/assert";
|
|
6
|
+
import defineProperties from "define-properties";
|
|
7
|
+
import shimUnscopables from "es-shim-unscopables";
|
|
8
|
+
import "es-iterator-helpers/Iterator.concat/auto";
|
|
9
|
+
import "es-iterator-helpers/Iterator.zip/auto";
|
|
10
|
+
import "es-iterator-helpers/Iterator.zipKeyed/auto";
|
|
6
11
|
// Object
|
|
7
|
-
Object
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!value || (typeof value !== "object" && typeof value !== "function")) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
if (value instanceof Error || value instanceof DOMException) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
const clone = structuredClone(value);
|
|
23
|
-
return clone instanceof Error || clone instanceof DOMException;
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
12
|
+
defineProperties(Object, {
|
|
13
|
+
get(obj, key) {
|
|
14
|
+
return Object.hasOwn(obj, key) ? Some(obj[key]) : None;
|
|
15
|
+
},
|
|
16
|
+
mapEntries(obj, fn) {
|
|
17
|
+
return Object.fromEntries(Object.entries(obj).map(fn));
|
|
18
|
+
},
|
|
19
|
+
});
|
|
29
20
|
// Map
|
|
30
|
-
Map.prototype
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
defineProperties(Map.prototype, {
|
|
22
|
+
getOrSet(key, defaultValue) {
|
|
23
|
+
const result = this.get(key);
|
|
24
|
+
if (result !== undefined) {
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
const newValue = defaultValue();
|
|
28
|
+
this.set(key, newValue);
|
|
29
|
+
return newValue;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
39
32
|
// Array
|
|
40
|
-
|
|
41
|
-
remove
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
if (index > this.length || index < 0) {
|
|
80
|
-
throw new RangeError(`Array.insert: index ${index} out of bounds`);
|
|
81
|
-
}
|
|
82
|
-
this.splice(index, 0, value);
|
|
83
|
-
return this;
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
insertOrdered: {
|
|
88
|
-
enumerable: false,
|
|
89
|
-
get() {
|
|
90
|
-
return function insertOrdered(value, cmp, duplicates = "high") {
|
|
91
|
-
return this.insert(value, (duplicates === "low" ? bisectLow : bisectHigh)(cmp, this, value));
|
|
92
|
-
};
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
present: {
|
|
96
|
-
enumerable: false,
|
|
97
|
-
get() {
|
|
98
|
-
return function present() {
|
|
99
|
-
return this.filter((value) => value !== undefined);
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
nonNullable: {
|
|
104
|
-
enumerable: false,
|
|
105
|
-
get() {
|
|
106
|
-
return function nonNullable() {
|
|
107
|
-
return this.filter((value) => value !== undefined);
|
|
108
|
-
};
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
get: {
|
|
112
|
-
enumerable: false,
|
|
113
|
-
get() {
|
|
114
|
-
return function get(index) {
|
|
115
|
-
return Object.get(this, index);
|
|
116
|
-
};
|
|
117
|
-
},
|
|
33
|
+
defineProperties(Array.prototype, {
|
|
34
|
+
remove(value) {
|
|
35
|
+
return this.removeIndex(this.indexOf(value));
|
|
36
|
+
},
|
|
37
|
+
removeFn(predicate) {
|
|
38
|
+
return this.removeIndex(this.findIndex(predicate));
|
|
39
|
+
},
|
|
40
|
+
removeIndex(index) {
|
|
41
|
+
if (!Number.isInteger(index)) {
|
|
42
|
+
throw new TypeError(`Array.removeIndex(): index ${index} is not an integer`);
|
|
43
|
+
}
|
|
44
|
+
if (index < 0 || index >= this.length) {
|
|
45
|
+
return None;
|
|
46
|
+
}
|
|
47
|
+
const removed = this.splice(index, 1).pop();
|
|
48
|
+
return Option.from(removed);
|
|
49
|
+
},
|
|
50
|
+
insert(value, index) {
|
|
51
|
+
if (!Number.isInteger(index)) {
|
|
52
|
+
throw new TypeError(`Array.insert(): index ${index} is not an integer`);
|
|
53
|
+
}
|
|
54
|
+
if (index > this.length || index < 0) {
|
|
55
|
+
throw new RangeError(`Array.insert: index ${index} out of bounds`);
|
|
56
|
+
}
|
|
57
|
+
this.splice(index, 0, value);
|
|
58
|
+
return this;
|
|
59
|
+
},
|
|
60
|
+
insertOrdered(value, cmp, duplicates = "high") {
|
|
61
|
+
return this.insert(value, (duplicates === "low" ? bisectLow : bisectHigh)(cmp, this, value));
|
|
62
|
+
},
|
|
63
|
+
present() {
|
|
64
|
+
return this.filter((value) => value !== undefined);
|
|
65
|
+
},
|
|
66
|
+
nonNullable() {
|
|
67
|
+
return this.filter((value) => value !== undefined);
|
|
68
|
+
},
|
|
69
|
+
get(index) {
|
|
70
|
+
return Object.get(this, index);
|
|
118
71
|
},
|
|
119
72
|
});
|
|
73
|
+
shimUnscopables("remove");
|
|
74
|
+
shimUnscopables("removeFn");
|
|
75
|
+
shimUnscopables("removeIndex");
|
|
76
|
+
shimUnscopables("insert");
|
|
77
|
+
shimUnscopables("insertOrdered");
|
|
78
|
+
shimUnscopables("present");
|
|
79
|
+
shimUnscopables("nonNullable");
|
|
80
|
+
shimUnscopables("get");
|
|
120
81
|
// Iterator
|
|
121
|
-
Iterator
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
82
|
+
defineProperties(Iterator, {
|
|
83
|
+
empty() {
|
|
84
|
+
return Iterator.from([]);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
defineProperties(Iterator.prototype, {
|
|
88
|
+
takeOne() {
|
|
89
|
+
const result = this.next();
|
|
90
|
+
return result.done === true ? None : Some(result.value);
|
|
91
|
+
},
|
|
92
|
+
takeWhile(predicate) {
|
|
93
|
+
const iter = this;
|
|
94
|
+
let index = 0;
|
|
95
|
+
let done = false;
|
|
96
|
+
return Iterator.from({
|
|
97
|
+
next() {
|
|
98
|
+
if (!done) {
|
|
99
|
+
const result = iter.next();
|
|
100
|
+
if (result.done === true) {
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
if (predicate(result.value, index++)) {
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
141
106
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
let done = false;
|
|
156
|
-
return Iterator.from({
|
|
157
|
-
next() {
|
|
158
|
-
if (!done) {
|
|
159
|
-
const result = iter.next();
|
|
160
|
-
if (result.done === true) {
|
|
161
|
-
return result;
|
|
107
|
+
done = true;
|
|
108
|
+
return { done: true, value: undefined };
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
skipWhile(predicate) {
|
|
113
|
+
const iter = this;
|
|
114
|
+
let index = 0;
|
|
115
|
+
let skipped = false;
|
|
116
|
+
return Iterator.from({
|
|
117
|
+
next() {
|
|
118
|
+
if (skipped) {
|
|
119
|
+
return iter.next();
|
|
162
120
|
}
|
|
163
|
-
|
|
164
|
-
|
|
121
|
+
while (true) {
|
|
122
|
+
const result = iter.next();
|
|
123
|
+
if (result.done === true) {
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
if (!predicate(result.value, index++)) {
|
|
127
|
+
skipped = true;
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
165
130
|
}
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
findMap(mapFn) {
|
|
135
|
+
let index = 0;
|
|
136
|
+
while (true) {
|
|
137
|
+
const result = this.next();
|
|
138
|
+
if (result.done === true) {
|
|
139
|
+
return undefined;
|
|
166
140
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
Iterator.prototype.skipWhile = function skipWhile(predicate) {
|
|
173
|
-
const iter = this;
|
|
174
|
-
let index = 0;
|
|
175
|
-
let skipped = false;
|
|
176
|
-
return Iterator.from({
|
|
177
|
-
next() {
|
|
178
|
-
if (skipped) {
|
|
179
|
-
return iter.next();
|
|
141
|
+
const mapped = mapFn(result.value, index++);
|
|
142
|
+
if (mapped !== undefined) {
|
|
143
|
+
return mapped;
|
|
180
144
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
partition(size) {
|
|
148
|
+
const iter = this;
|
|
149
|
+
let done = false;
|
|
150
|
+
return Iterator.from({
|
|
151
|
+
next() {
|
|
152
|
+
if (done) {
|
|
153
|
+
return { done: true, value: undefined };
|
|
185
154
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
155
|
+
const part = [];
|
|
156
|
+
while (true) {
|
|
157
|
+
const result = iter.next();
|
|
158
|
+
if (result.done === true) {
|
|
159
|
+
done = true;
|
|
160
|
+
return part.length > 0
|
|
161
|
+
? { done: false, value: part }
|
|
162
|
+
: { done: true, value: undefined };
|
|
163
|
+
}
|
|
164
|
+
part.push(result.value);
|
|
165
|
+
if (part.length === size) {
|
|
166
|
+
return { done: false, value: part };
|
|
167
|
+
}
|
|
189
168
|
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
199
|
-
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
frontBiasedPartition(size) {
|
|
173
|
+
const input = this.toArray();
|
|
174
|
+
let inputPos = 0;
|
|
175
|
+
const firstLength = input.length % size;
|
|
176
|
+
const output = [];
|
|
177
|
+
if (firstLength > 0) {
|
|
178
|
+
output.push(input.slice(0, firstLength));
|
|
179
|
+
inputPos = firstLength;
|
|
200
180
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
181
|
+
while (inputPos < input.length) {
|
|
182
|
+
output.push(input.slice(inputPos, inputPos + size));
|
|
183
|
+
inputPos += size;
|
|
204
184
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const part = [];
|
|
216
|
-
while (true) {
|
|
217
|
-
const result = iter.next();
|
|
218
|
-
if (result.done === true) {
|
|
219
|
-
done = true;
|
|
220
|
-
return part.length > 0
|
|
221
|
-
? { done: false, value: part }
|
|
222
|
-
: { done: true, value: undefined };
|
|
223
|
-
}
|
|
224
|
-
part.push(result.value);
|
|
225
|
-
if (part.length === size) {
|
|
226
|
-
return { done: false, value: part };
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
});
|
|
231
|
-
};
|
|
232
|
-
Iterator.prototype.frontBiasedPartition = function frontBiasedPartition(size) {
|
|
233
|
-
const input = this.toArray();
|
|
234
|
-
let inputPos = 0;
|
|
235
|
-
const firstLength = input.length % size;
|
|
236
|
-
const output = [];
|
|
237
|
-
if (firstLength > 0) {
|
|
238
|
-
output.push(input.slice(0, firstLength));
|
|
239
|
-
inputPos = firstLength;
|
|
240
|
-
}
|
|
241
|
-
while (inputPos < input.length) {
|
|
242
|
-
output.push(input.slice(inputPos, inputPos + size));
|
|
243
|
-
inputPos += size;
|
|
244
|
-
}
|
|
245
|
-
assert(inputPos === input.length);
|
|
246
|
-
return output;
|
|
247
|
-
};
|
|
248
|
-
Iterator.prototype.present = function present() {
|
|
249
|
-
return Iterator.from(this.filter((item) => item !== undefined));
|
|
250
|
-
};
|
|
251
|
-
Iterator.prototype.nonNullable = function nonNullable() {
|
|
252
|
-
return Iterator.from(this.filter((item) => item !== undefined && item !== null));
|
|
253
|
-
};
|
|
185
|
+
assert(inputPos === input.length);
|
|
186
|
+
return output;
|
|
187
|
+
},
|
|
188
|
+
present() {
|
|
189
|
+
return Iterator.from(this.filter((item) => item !== undefined));
|
|
190
|
+
},
|
|
191
|
+
nonNullable() {
|
|
192
|
+
return Iterator.from(this.filter((item) => item !== undefined && item !== null));
|
|
193
|
+
},
|
|
194
|
+
});
|
|
254
195
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/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AAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAsB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC;IACxF,CAAC;IAED,WAAW;QACP,OAAO,QAAQ,CAAC,IAAI,CAChB,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAA0B,EAAE,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,CAAC,CACrF,CAAC;IACN,CAAC;CACJ,CAAC,CAAC"}
|
package/dist/index.test.js
CHANGED
package/dist/index.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,GAAG,CAAC;AAEX,OAAO,mBAAmB,CAAC;AAE3B,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC;AAErC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE;IACpB,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IACvC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7C,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,aAAa,EAAkB,CAAC;IACrE,MAAM,CAAC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AAE,GAAG,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,iBAAiB,EAAE,GAAG,EAAE;IACzB,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE;IACvB,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;AACxC,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bodil/monkey-business",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Let's give JS core types a polish",
|
|
5
|
+
"homepage": "https://codeberg.org/bodil/monkey-business",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
|
-
"url": "git
|
|
8
|
+
"url": "ssh://git@codeberg.org/bodil/monkey-business.git"
|
|
8
9
|
},
|
|
9
10
|
"license": "EUPL-1.2+",
|
|
10
11
|
"module": "dist/index.js",
|
|
@@ -25,26 +26,35 @@
|
|
|
25
26
|
"access": "public"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@bodil/core": "^0.
|
|
29
|
-
"@bodil/opt": "^0.
|
|
29
|
+
"@bodil/core": "^0.3.0",
|
|
30
|
+
"@bodil/opt": "^0.4.1",
|
|
31
|
+
"@types/define-properties": "^1.1.5",
|
|
32
|
+
"define-properties": "^1.2.1",
|
|
33
|
+
"es-iterator-helpers": "^1.2.1",
|
|
34
|
+
"es-shim-unscopables": "^1.1.0"
|
|
30
35
|
},
|
|
31
36
|
"devDependencies": {
|
|
32
|
-
"@bodil/opt-vitest": "^1.
|
|
37
|
+
"@bodil/opt-vitest": "^1.1.0",
|
|
33
38
|
"@eslint/eslintrc": "^3.3.1",
|
|
34
|
-
"@eslint/js": "^9.
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
36
|
-
"@typescript-eslint/parser": "^8.
|
|
37
|
-
"eslint": "^9.
|
|
38
|
-
"eslint-config-prettier": "^10.1.
|
|
39
|
-
"eslint-plugin-jsdoc": "^
|
|
40
|
-
"globals": "^
|
|
41
|
-
"
|
|
42
|
-
"
|
|
39
|
+
"@eslint/js": "^9.33.0",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^8.39.1",
|
|
41
|
+
"@typescript-eslint/parser": "^8.39.1",
|
|
42
|
+
"eslint": "^9.33.0",
|
|
43
|
+
"eslint-config-prettier": "^10.1.8",
|
|
44
|
+
"eslint-plugin-jsdoc": "^54.0.0",
|
|
45
|
+
"globals": "^16.3.0",
|
|
46
|
+
"typedoc": "^0.28.10",
|
|
47
|
+
"typedoc-plugin-extras": "^4.0.1",
|
|
48
|
+
"typedoc-plugin-mdn-links": "^5.0.8",
|
|
49
|
+
"typescript": "^5.9.2",
|
|
50
|
+
"vitest": "^3.2.4"
|
|
43
51
|
},
|
|
44
52
|
"scripts": {
|
|
45
53
|
"build": "tsc",
|
|
46
54
|
"test": "vitest --run",
|
|
47
55
|
"lint": "eslint src",
|
|
56
|
+
"doc": "typedoc",
|
|
57
|
+
"doc:readthedocs": "typedoc --out $READTHEDOCS_OUTPUT/html",
|
|
48
58
|
"prepublish": "tsc"
|
|
49
59
|
}
|
|
50
60
|
}
|
package/src/index.test.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,8 +5,17 @@ import { None, Option, Some } from "@bodil/opt";
|
|
|
5
5
|
import { type OrderFn, bisectHigh, bisectLow } from "@bodil/core/order";
|
|
6
6
|
import type { Present } from "@bodil/core/types";
|
|
7
7
|
import { assert } from "@bodil/core/assert";
|
|
8
|
+
import defineProperties from "define-properties";
|
|
9
|
+
import shimUnscopables from "es-shim-unscopables";
|
|
10
|
+
|
|
11
|
+
import "es-iterator-helpers/Iterator.concat/auto";
|
|
12
|
+
import "es-iterator-helpers/Iterator.zip/auto";
|
|
13
|
+
import "es-iterator-helpers/Iterator.zipKeyed/auto";
|
|
8
14
|
|
|
9
15
|
declare global {
|
|
16
|
+
/**
|
|
17
|
+
* Added methods on the {@link Object} global object.
|
|
18
|
+
*/
|
|
10
19
|
interface ObjectConstructor {
|
|
11
20
|
/**
|
|
12
21
|
* Checked key lookup. Returns {@link None} if a key isn't present.
|
|
@@ -25,10 +34,9 @@ declare global {
|
|
|
25
34
|
): Record<string, B>;
|
|
26
35
|
}
|
|
27
36
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Added methods on {@link Map}s.
|
|
39
|
+
*/
|
|
32
40
|
interface Map<K, V> {
|
|
33
41
|
/**
|
|
34
42
|
* If `key` exists in the map, return the value associated with it.
|
|
@@ -38,6 +46,9 @@ declare global {
|
|
|
38
46
|
getOrSet(key: K, defaultValue: () => V): V;
|
|
39
47
|
}
|
|
40
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Added methods on {@link Array}s.
|
|
51
|
+
*/
|
|
41
52
|
interface Array<T> {
|
|
42
53
|
/**
|
|
43
54
|
* Insert `value` at `index` in the array.
|
|
@@ -100,6 +111,9 @@ declare global {
|
|
|
100
111
|
get(index: number): Option<T>;
|
|
101
112
|
}
|
|
102
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Added methods on the {@link Iterator} global object.
|
|
116
|
+
*/
|
|
103
117
|
interface IteratorConstructor {
|
|
104
118
|
/**
|
|
105
119
|
* Construct an empty iterator.
|
|
@@ -107,9 +121,17 @@ declare global {
|
|
|
107
121
|
empty<T>(): IteratorObject<T>;
|
|
108
122
|
/**
|
|
109
123
|
* Sequence multiple iterators into a single one.
|
|
110
|
-
*
|
|
124
|
+
* @see https://github.com/tc39/proposal-iterator-sequencing
|
|
111
125
|
*/
|
|
112
126
|
concat<T>(...inputs: Array<Iterable<T>>): IteratorObject<T>;
|
|
127
|
+
/**
|
|
128
|
+
* @see https://github.com/tc39/proposal-joint-iteration
|
|
129
|
+
*/
|
|
130
|
+
zip<T>(inputs: Iterable<Iterable<T>>): IteratorObject<Array<T>>;
|
|
131
|
+
/**
|
|
132
|
+
* @see https://github.com/tc39/proposal-joint-iteration
|
|
133
|
+
*/
|
|
134
|
+
zipKeyed<T>(inputs: Record<string, Iterable<T>>): IteratorObject<Record<string, T>>;
|
|
113
135
|
}
|
|
114
136
|
|
|
115
137
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -117,8 +139,6 @@ declare global {
|
|
|
117
139
|
/**
|
|
118
140
|
* Get the next value from the iterator, wrapped in an {@link Option}
|
|
119
141
|
* type. If the iterator has no more values, return {@link None}.
|
|
120
|
-
*
|
|
121
|
-
* This is the nicely utility typed version of {@link Iterator#next}.
|
|
122
142
|
*/
|
|
123
143
|
takeOne(): Option<T>;
|
|
124
144
|
/**
|
|
@@ -127,6 +147,7 @@ declare global {
|
|
|
127
147
|
takeWhile<S extends T>(
|
|
128
148
|
predicate: (value: T, index: number) => value is S
|
|
129
149
|
): IteratorObject<S, undefined>;
|
|
150
|
+
/** @ignore */
|
|
130
151
|
takeWhile(predicate: (value: T, index: number) => boolean): IteratorObject<T, undefined>;
|
|
131
152
|
/**
|
|
132
153
|
* Ignore all items matching `predicate` until the first item that
|
|
@@ -164,308 +185,237 @@ declare global {
|
|
|
164
185
|
|
|
165
186
|
// Object
|
|
166
187
|
|
|
167
|
-
Object
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
Object.mapEntries = function mapEntries<A, B>(
|
|
172
|
-
obj: Record<string, A>,
|
|
173
|
-
fn: (entry: [key: string, value: A]) => [string, B]
|
|
174
|
-
): Record<string, B> {
|
|
175
|
-
return Object.fromEntries(Object.entries(obj).map(fn));
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// Error
|
|
179
|
-
|
|
180
|
-
Error.isError ??= function isError(value: unknown): value is Error {
|
|
181
|
-
if (!value || (typeof value !== "object" && typeof value !== "function")) {
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (value instanceof Error || value instanceof DOMException) {
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
188
|
+
defineProperties(Object, {
|
|
189
|
+
get<O extends object, K extends keyof O>(obj: O, key: K): Option<O[K]> {
|
|
190
|
+
return Object.hasOwn(obj, key) ? Some(obj[key]) : None;
|
|
191
|
+
},
|
|
188
192
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return
|
|
194
|
-
}
|
|
195
|
-
};
|
|
193
|
+
mapEntries<A, B>(
|
|
194
|
+
obj: Record<string, A>,
|
|
195
|
+
fn: (entry: [key: string, value: A]) => [string, B]
|
|
196
|
+
): Record<string, B> {
|
|
197
|
+
return Object.fromEntries(Object.entries(obj).map(fn));
|
|
198
|
+
},
|
|
199
|
+
});
|
|
196
200
|
|
|
197
201
|
// Map
|
|
198
202
|
|
|
199
|
-
Map.prototype
|
|
200
|
-
this: Map<K, NonNullable<V>>,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return newValue;
|
|
211
|
-
};
|
|
203
|
+
defineProperties(Map.prototype, {
|
|
204
|
+
getOrSet<K, V>(this: Map<K, NonNullable<V>>, key: K, defaultValue: () => NonNullable<V>): V {
|
|
205
|
+
const result = this.get(key);
|
|
206
|
+
if (result !== undefined) {
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
const newValue = defaultValue();
|
|
210
|
+
this.set(key, newValue);
|
|
211
|
+
return newValue;
|
|
212
|
+
},
|
|
213
|
+
});
|
|
212
214
|
|
|
213
215
|
// Array
|
|
214
216
|
|
|
215
|
-
|
|
216
|
-
remove: {
|
|
217
|
-
|
|
218
|
-
get() {
|
|
219
|
-
return function remove<T>(this: Array<T>, value: T): Option<T> {
|
|
220
|
-
return this.removeIndex(this.indexOf(value));
|
|
221
|
-
};
|
|
222
|
-
},
|
|
217
|
+
defineProperties(Array.prototype, {
|
|
218
|
+
remove<T>(this: Array<T>, value: T): Option<T> {
|
|
219
|
+
return this.removeIndex(this.indexOf(value));
|
|
223
220
|
},
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
): Option<T> {
|
|
231
|
-
return this.removeIndex(this.findIndex(predicate as () => boolean));
|
|
232
|
-
};
|
|
233
|
-
},
|
|
221
|
+
|
|
222
|
+
removeFn<T>(
|
|
223
|
+
this: Array<T>,
|
|
224
|
+
predicate: (value: T, index: number, obj: Array<T>) => boolean
|
|
225
|
+
): Option<T> {
|
|
226
|
+
return this.removeIndex(this.findIndex(predicate as () => boolean));
|
|
234
227
|
},
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const removed = this.splice(index, 1).pop();
|
|
246
|
-
return Option.from(removed);
|
|
247
|
-
};
|
|
248
|
-
},
|
|
228
|
+
|
|
229
|
+
removeIndex<T>(this: Array<T>, index: number): Option<T> {
|
|
230
|
+
if (!Number.isInteger(index)) {
|
|
231
|
+
throw new TypeError(`Array.removeIndex(): index ${index} is not an integer`);
|
|
232
|
+
}
|
|
233
|
+
if (index < 0 || index >= this.length) {
|
|
234
|
+
return None;
|
|
235
|
+
}
|
|
236
|
+
const removed = this.splice(index, 1).pop();
|
|
237
|
+
return Option.from(removed);
|
|
249
238
|
},
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
this.splice(index, 0, value);
|
|
261
|
-
return this;
|
|
262
|
-
};
|
|
263
|
-
},
|
|
239
|
+
|
|
240
|
+
insert<T>(this: Array<T>, value: T, index: number): Array<T> {
|
|
241
|
+
if (!Number.isInteger(index)) {
|
|
242
|
+
throw new TypeError(`Array.insert(): index ${index} is not an integer`);
|
|
243
|
+
}
|
|
244
|
+
if (index > this.length || index < 0) {
|
|
245
|
+
throw new RangeError(`Array.insert: index ${index} out of bounds`);
|
|
246
|
+
}
|
|
247
|
+
this.splice(index, 0, value);
|
|
248
|
+
return this;
|
|
264
249
|
},
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
(duplicates === "low" ? bisectLow : bisectHigh)(cmp, this, value)
|
|
277
|
-
);
|
|
278
|
-
};
|
|
279
|
-
},
|
|
250
|
+
|
|
251
|
+
insertOrdered<T>(
|
|
252
|
+
this: Array<T>,
|
|
253
|
+
value: T,
|
|
254
|
+
cmp: OrderFn<T>,
|
|
255
|
+
duplicates: "low" | "high" = "high"
|
|
256
|
+
): Array<T> {
|
|
257
|
+
return this.insert(
|
|
258
|
+
value,
|
|
259
|
+
(duplicates === "low" ? bisectLow : bisectHigh)(cmp, this, value)
|
|
260
|
+
);
|
|
280
261
|
},
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return function present<T>(this: Array<T>): Array<Present<T>> {
|
|
285
|
-
return this.filter((value: T): value is Present<T> => value !== undefined);
|
|
286
|
-
};
|
|
287
|
-
},
|
|
262
|
+
|
|
263
|
+
present<T>(this: Array<T>): Array<Present<T>> {
|
|
264
|
+
return this.filter((value: T): value is Present<T> => value !== undefined);
|
|
288
265
|
},
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return function nonNullable<T>(this: Array<T>): Array<NonNullable<T>> {
|
|
293
|
-
return this.filter((value: T): value is NonNullable<T> => value !== undefined);
|
|
294
|
-
};
|
|
295
|
-
},
|
|
266
|
+
|
|
267
|
+
nonNullable<T>(this: Array<T>): Array<NonNullable<T>> {
|
|
268
|
+
return this.filter((value: T): value is NonNullable<T> => value !== undefined);
|
|
296
269
|
},
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
get()
|
|
300
|
-
return function get<T>(this: Array<T>, index: number): Option<T> {
|
|
301
|
-
return Object.get(this, index);
|
|
302
|
-
};
|
|
303
|
-
},
|
|
270
|
+
|
|
271
|
+
get<T>(this: Array<T>, index: number): Option<T> {
|
|
272
|
+
return Object.get(this, index);
|
|
304
273
|
},
|
|
305
274
|
});
|
|
306
275
|
|
|
276
|
+
shimUnscopables("remove");
|
|
277
|
+
shimUnscopables("removeFn");
|
|
278
|
+
shimUnscopables("removeIndex");
|
|
279
|
+
shimUnscopables("insert");
|
|
280
|
+
shimUnscopables("insertOrdered");
|
|
281
|
+
shimUnscopables("present");
|
|
282
|
+
shimUnscopables("nonNullable");
|
|
283
|
+
shimUnscopables("get");
|
|
284
|
+
|
|
307
285
|
// Iterator
|
|
308
286
|
|
|
309
|
-
Iterator
|
|
310
|
-
|
|
311
|
-
|
|
287
|
+
defineProperties(Iterator, {
|
|
288
|
+
empty<T>(): IteratorObject<T> {
|
|
289
|
+
return Iterator.from([]);
|
|
290
|
+
},
|
|
291
|
+
});
|
|
312
292
|
|
|
313
|
-
Iterator.
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
if (
|
|
329
|
-
|
|
293
|
+
defineProperties(Iterator.prototype, {
|
|
294
|
+
takeOne<T>(this: Iterator<T>): Option<T> {
|
|
295
|
+
const result = this.next();
|
|
296
|
+
return result.done === true ? None : Some(result.value);
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
takeWhile<T>(
|
|
300
|
+
this: IteratorObject<T, undefined>,
|
|
301
|
+
predicate: (value: T, index: number) => boolean
|
|
302
|
+
): IteratorObject<T, undefined> {
|
|
303
|
+
const iter = this;
|
|
304
|
+
let index = 0;
|
|
305
|
+
let done = false;
|
|
306
|
+
return Iterator.from<T>({
|
|
307
|
+
next(): IteratorResult<T, undefined> {
|
|
308
|
+
if (!done) {
|
|
309
|
+
const result = iter.next();
|
|
310
|
+
if (result.done === true) {
|
|
311
|
+
return result;
|
|
312
|
+
}
|
|
313
|
+
if (predicate(result.value, index++)) {
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
330
316
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
)
|
|
347
|
-
|
|
348
|
-
let index = 0;
|
|
349
|
-
let done = false;
|
|
350
|
-
return Iterator.from<T>({
|
|
351
|
-
next(): IteratorResult<T, undefined> {
|
|
352
|
-
if (!done) {
|
|
353
|
-
const result = iter.next();
|
|
354
|
-
if (result.done === true) {
|
|
355
|
-
return result;
|
|
317
|
+
done = true;
|
|
318
|
+
return { done: true, value: undefined };
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
skipWhile<T>(
|
|
324
|
+
this: IteratorObject<T, undefined>,
|
|
325
|
+
predicate: (value: T, index: number) => boolean
|
|
326
|
+
): IteratorObject<T, undefined> {
|
|
327
|
+
const iter = this;
|
|
328
|
+
let index = 0;
|
|
329
|
+
let skipped = false;
|
|
330
|
+
return Iterator.from<T>({
|
|
331
|
+
next(): IteratorResult<T, undefined> {
|
|
332
|
+
if (skipped) {
|
|
333
|
+
return iter.next();
|
|
356
334
|
}
|
|
357
|
-
|
|
358
|
-
|
|
335
|
+
while (true) {
|
|
336
|
+
const result = iter.next();
|
|
337
|
+
if (result.done === true) {
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
340
|
+
if (!predicate(result.value, index++)) {
|
|
341
|
+
skipped = true;
|
|
342
|
+
return result;
|
|
343
|
+
}
|
|
359
344
|
}
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
findMap<T, U>(
|
|
350
|
+
this: IteratorObject<T, undefined>,
|
|
351
|
+
mapFn: (value: T, index: number) => NonNullable<U> | undefined
|
|
352
|
+
): NonNullable<U> | undefined {
|
|
353
|
+
let index = 0;
|
|
354
|
+
while (true) {
|
|
355
|
+
const result = this.next();
|
|
356
|
+
if (result.done === true) {
|
|
357
|
+
return undefined;
|
|
360
358
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
});
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
Iterator.prototype.skipWhile = function skipWhile<T>(
|
|
368
|
-
this: IteratorObject<T, undefined>,
|
|
369
|
-
predicate: (value: T, index: number) => boolean
|
|
370
|
-
): IteratorObject<T, undefined> {
|
|
371
|
-
const iter = this;
|
|
372
|
-
let index = 0;
|
|
373
|
-
let skipped = false;
|
|
374
|
-
return Iterator.from<T>({
|
|
375
|
-
next(): IteratorResult<T, undefined> {
|
|
376
|
-
if (skipped) {
|
|
377
|
-
return iter.next();
|
|
359
|
+
const mapped = mapFn(result.value, index++);
|
|
360
|
+
if (mapped !== undefined) {
|
|
361
|
+
return mapped;
|
|
378
362
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
partition<T>(
|
|
367
|
+
this: IteratorObject<T, undefined>,
|
|
368
|
+
size: number
|
|
369
|
+
): IteratorObject<Array<T>, undefined> {
|
|
370
|
+
const iter = this;
|
|
371
|
+
let done = false;
|
|
372
|
+
return Iterator.from<Array<T>>({
|
|
373
|
+
next(): IteratorResult<Array<T>, undefined> {
|
|
374
|
+
if (done) {
|
|
375
|
+
return { done: true, value: undefined };
|
|
383
376
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
377
|
+
const part = [];
|
|
378
|
+
while (true) {
|
|
379
|
+
const result = iter.next();
|
|
380
|
+
if (result.done === true) {
|
|
381
|
+
done = true;
|
|
382
|
+
return part.length > 0
|
|
383
|
+
? { done: false, value: part }
|
|
384
|
+
: { done: true, value: undefined };
|
|
385
|
+
}
|
|
386
|
+
part.push(result.value);
|
|
387
|
+
if (part.length === size) {
|
|
388
|
+
return { done: false, value: part };
|
|
389
|
+
}
|
|
387
390
|
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (result.done === true) {
|
|
401
|
-
return undefined;
|
|
391
|
+
},
|
|
392
|
+
});
|
|
393
|
+
},
|
|
394
|
+
|
|
395
|
+
frontBiasedPartition<T>(this: IteratorObject<T, undefined>, size: number): Array<Array<T>> {
|
|
396
|
+
const input = this.toArray();
|
|
397
|
+
let inputPos = 0;
|
|
398
|
+
const firstLength = input.length % size;
|
|
399
|
+
const output: Array<Array<T>> = [];
|
|
400
|
+
if (firstLength > 0) {
|
|
401
|
+
output.push(input.slice(0, firstLength));
|
|
402
|
+
inputPos = firstLength;
|
|
402
403
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
404
|
+
while (inputPos < input.length) {
|
|
405
|
+
output.push(input.slice(inputPos, inputPos + size));
|
|
406
|
+
inputPos += size;
|
|
406
407
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
this: IteratorObject<T, undefined>,
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
const part = [];
|
|
422
|
-
while (true) {
|
|
423
|
-
const result = iter.next();
|
|
424
|
-
if (result.done === true) {
|
|
425
|
-
done = true;
|
|
426
|
-
return part.length > 0
|
|
427
|
-
? { done: false, value: part }
|
|
428
|
-
: { done: true, value: undefined };
|
|
429
|
-
}
|
|
430
|
-
part.push(result.value);
|
|
431
|
-
if (part.length === size) {
|
|
432
|
-
return { done: false, value: part };
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
},
|
|
436
|
-
});
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
Iterator.prototype.frontBiasedPartition = function frontBiasedPartition<T>(
|
|
440
|
-
this: IteratorObject<T, undefined>,
|
|
441
|
-
size: number
|
|
442
|
-
): Array<Array<T>> {
|
|
443
|
-
const input = this.toArray();
|
|
444
|
-
let inputPos = 0;
|
|
445
|
-
const firstLength = input.length % size;
|
|
446
|
-
const output: Array<Array<T>> = [];
|
|
447
|
-
if (firstLength > 0) {
|
|
448
|
-
output.push(input.slice(0, firstLength));
|
|
449
|
-
inputPos = firstLength;
|
|
450
|
-
}
|
|
451
|
-
while (inputPos < input.length) {
|
|
452
|
-
output.push(input.slice(inputPos, inputPos + size));
|
|
453
|
-
inputPos += size;
|
|
454
|
-
}
|
|
455
|
-
assert(inputPos === input.length);
|
|
456
|
-
return output;
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
Iterator.prototype.present = function present<T>(
|
|
460
|
-
this: IteratorObject<T, undefined>
|
|
461
|
-
): IteratorObject<Present<T>, undefined> {
|
|
462
|
-
return Iterator.from(this.filter((item): item is Present<T> => item !== undefined));
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
Iterator.prototype.nonNullable = function nonNullable<T>(
|
|
466
|
-
this: IteratorObject<T, undefined>
|
|
467
|
-
): IteratorObject<NonNullable<T>, undefined> {
|
|
468
|
-
return Iterator.from(
|
|
469
|
-
this.filter((item): item is NonNullable<T> => item !== undefined && item !== null)
|
|
470
|
-
);
|
|
471
|
-
};
|
|
408
|
+
assert(inputPos === input.length);
|
|
409
|
+
return output;
|
|
410
|
+
},
|
|
411
|
+
|
|
412
|
+
present<T>(this: IteratorObject<T, undefined>): IteratorObject<Present<T>, undefined> {
|
|
413
|
+
return Iterator.from(this.filter((item): item is Present<T> => item !== undefined));
|
|
414
|
+
},
|
|
415
|
+
|
|
416
|
+
nonNullable<T>(this: IteratorObject<T, undefined>): IteratorObject<NonNullable<T>, undefined> {
|
|
417
|
+
return Iterator.from(
|
|
418
|
+
this.filter((item): item is NonNullable<T> => item !== undefined && item !== null)
|
|
419
|
+
);
|
|
420
|
+
},
|
|
421
|
+
});
|