@rimbu/base 2.0.1 → 2.0.3
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/README.md +183 -26
- package/dist/bun/arr.mts +184 -19
- package/dist/bun/entry.mts +14 -2
- package/dist/bun/index.mts +10 -0
- package/dist/bun/rimbu-error.mts +25 -0
- package/dist/bun/token.mts +7 -0
- package/dist/cjs/arr.cjs +209 -44
- package/dist/cjs/arr.cjs.map +1 -1
- package/dist/cjs/arr.d.cts +184 -0
- package/dist/cjs/entry.cjs +16 -5
- package/dist/cjs/entry.cjs.map +1 -1
- package/dist/cjs/entry.d.cts +14 -0
- package/dist/cjs/index.cjs +10 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +9 -0
- package/dist/cjs/plain-object.cjs +2 -3
- package/dist/cjs/plain-object.cjs.map +1 -1
- package/dist/cjs/rimbu-error.cjs +30 -5
- package/dist/cjs/rimbu-error.cjs.map +1 -1
- package/dist/cjs/rimbu-error.d.cts +25 -0
- package/dist/cjs/token.cjs +4 -0
- package/dist/cjs/token.cjs.map +1 -1
- package/dist/cjs/token.d.cts +7 -0
- package/dist/esm/arr.d.mts +184 -0
- package/dist/esm/arr.mjs +184 -19
- package/dist/esm/arr.mjs.map +1 -1
- package/dist/esm/entry.d.mts +14 -0
- package/dist/esm/entry.mjs +14 -2
- package/dist/esm/entry.mjs.map +1 -1
- package/dist/esm/index.d.mts +9 -0
- package/dist/esm/index.mjs +10 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/rimbu-error.d.mts +25 -0
- package/dist/esm/rimbu-error.mjs +25 -0
- package/dist/esm/rimbu-error.mjs.map +1 -1
- package/dist/esm/token.d.mts +7 -0
- package/dist/esm/token.mjs +4 -0
- package/dist/esm/token.mjs.map +1 -1
- package/package.json +5 -5
- package/src/arr.mts +184 -19
- package/src/entry.mts +14 -2
- package/src/index.mts +10 -0
- package/src/rimbu-error.mts +25 -0
- package/src/token.mts +7 -0
package/dist/bun/rimbu-error.mts
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { ErrBase } from '@rimbu/common';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Error thrown when an operation assumes a collection is non-empty but it is empty.
|
|
5
|
+
*/
|
|
3
6
|
export class EmptyCollectionAssumedNonEmptyError extends ErrBase.CustomError {
|
|
4
7
|
constructor() {
|
|
5
8
|
super('empty collection was assumbed to be non-empty');
|
|
6
9
|
}
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Error thrown when a builder is modified while it is being iterated.
|
|
14
|
+
*/
|
|
9
15
|
export class ModifiedBuilderWhileLoopingOverItError extends ErrBase.CustomError {
|
|
10
16
|
constructor() {
|
|
11
17
|
super('an attempt was made to modify a builder while looping over it');
|
|
12
18
|
}
|
|
13
19
|
}
|
|
14
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Error indicating an unexpected internal state. Users are encouraged to file an issue.
|
|
23
|
+
*/
|
|
15
24
|
export class InvalidStateError extends ErrBase.CustomError {
|
|
16
25
|
constructor() {
|
|
17
26
|
super(
|
|
@@ -20,20 +29,36 @@ export class InvalidStateError extends ErrBase.CustomError {
|
|
|
20
29
|
}
|
|
21
30
|
}
|
|
22
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Error indicating incorrect usage of the API.
|
|
34
|
+
*/
|
|
23
35
|
export class InvalidUsageError extends ErrBase.CustomError {}
|
|
24
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Throws an `EmptyCollectionAssumedNonEmptyError`.
|
|
39
|
+
*/
|
|
25
40
|
export function throwEmptyCollectionAssumedNonEmptyError(): never {
|
|
26
41
|
throw new EmptyCollectionAssumedNonEmptyError();
|
|
27
42
|
}
|
|
28
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Throws a `ModifiedBuilderWhileLoopingOverItError`.
|
|
46
|
+
*/
|
|
29
47
|
export function throwModifiedBuilderWhileLoopingOverItError(): never {
|
|
30
48
|
throw new ModifiedBuilderWhileLoopingOverItError();
|
|
31
49
|
}
|
|
32
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Throws an `InvalidStateError`.
|
|
53
|
+
*/
|
|
33
54
|
export function throwInvalidStateError(): never {
|
|
34
55
|
throw new InvalidStateError();
|
|
35
56
|
}
|
|
36
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Throws an `InvalidUsageError` with the provided message.
|
|
60
|
+
* @param msg - context message describing the invalid usage
|
|
61
|
+
*/
|
|
37
62
|
export function throwInvalidUsageError(msg: string): never {
|
|
38
63
|
throw new InvalidUsageError(msg);
|
|
39
64
|
}
|
package/dist/bun/token.mts
CHANGED
package/dist/cjs/arr.cjs
CHANGED
|
@@ -1,21 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.splice = exports.insert = exports.mod = exports.update = exports.last = exports.prepend = exports.reverse = exports.append = void 0;
|
|
4
|
+
exports._appendNew = _appendNew;
|
|
5
|
+
exports._appendOld = _appendOld;
|
|
6
|
+
exports.concat = concat;
|
|
7
|
+
exports._reverseNew = _reverseNew;
|
|
8
|
+
exports._reverseOld = _reverseOld;
|
|
9
|
+
exports.forEach = forEach;
|
|
10
|
+
exports.map = map;
|
|
11
|
+
exports.reverseMap = reverseMap;
|
|
12
|
+
exports._prependNew = _prependNew;
|
|
13
|
+
exports._prependOld = _prependOld;
|
|
14
|
+
exports._lastNew = _lastNew;
|
|
15
|
+
exports._lastOld = _lastOld;
|
|
16
|
+
exports._updateNew = _updateNew;
|
|
17
|
+
exports._updateOld = _updateOld;
|
|
18
|
+
exports._modNew = _modNew;
|
|
19
|
+
exports._modOld = _modOld;
|
|
20
|
+
exports._insertNew = _insertNew;
|
|
21
|
+
exports._insertOld = _insertOld;
|
|
22
|
+
exports.tail = tail;
|
|
23
|
+
exports.init = init;
|
|
24
|
+
exports._spliceNew = _spliceNew;
|
|
25
|
+
exports._spliceOld = _spliceOld;
|
|
26
|
+
exports.copySparse = copySparse;
|
|
27
|
+
exports.mapSparse = mapSparse;
|
|
4
28
|
var tslib_1 = require("tslib");
|
|
5
29
|
var common_1 = require("@rimbu/common");
|
|
30
|
+
/**
|
|
31
|
+
* Internal helper that appends a value using the modern immutable `toSpliced` API.
|
|
32
|
+
* @internal
|
|
33
|
+
* @typeparam T - the array element type
|
|
34
|
+
* @param array - the source array (not mutated)
|
|
35
|
+
* @param value - the value to append
|
|
36
|
+
* @returns a new non-empty array with the value at the end
|
|
37
|
+
*/
|
|
6
38
|
function _appendNew(array, value) {
|
|
7
39
|
return array.toSpliced(array.length, 0, value);
|
|
8
40
|
}
|
|
9
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Internal helper that appends a value by cloning and pushing (legacy fallback).
|
|
43
|
+
* @internal
|
|
44
|
+
* @typeparam T - the array element type
|
|
45
|
+
* @param array - the source array (not mutated)
|
|
46
|
+
* @param value - the value to append
|
|
47
|
+
* @returns a new non-empty array with the value at the end
|
|
48
|
+
*/
|
|
10
49
|
function _appendOld(array, value) {
|
|
11
50
|
var clone = array.slice();
|
|
12
51
|
clone.push(value);
|
|
13
52
|
return clone;
|
|
14
53
|
}
|
|
15
|
-
|
|
16
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Returns a copy of the array with the given value appended.
|
|
56
|
+
* Chooses an implementation depending on environment capabilities.
|
|
57
|
+
* @typeparam T - the array element type
|
|
58
|
+
* @param array - the source array (not mutated)
|
|
59
|
+
* @param value - the value to append
|
|
60
|
+
* @returns a new array with the value at the end
|
|
61
|
+
*/
|
|
17
62
|
exports.append = "toSpliced" in Array.prototype ? _appendNew : _appendOld;
|
|
18
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Returns the concatenation of two arrays, reusing an input array when the other is empty.
|
|
65
|
+
* @typeparam T - the array element type
|
|
66
|
+
* @param first - the first array
|
|
67
|
+
* @param second - the second array
|
|
68
|
+
* @returns a new array containing all elements of both arrays (or one of the originals if the other is empty)
|
|
69
|
+
*/
|
|
19
70
|
function concat(first, second) {
|
|
20
71
|
if (first.length === 0)
|
|
21
72
|
return second;
|
|
@@ -23,14 +74,20 @@ function concat(first, second) {
|
|
|
23
74
|
return first;
|
|
24
75
|
return first.concat(second);
|
|
25
76
|
}
|
|
26
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Internal helper to create a reversed copy using modern `toReversed` with optional slicing.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
27
81
|
function _reverseNew(array, start, end) {
|
|
28
82
|
var source = undefined !== start || undefined !== end
|
|
29
83
|
? array.slice(start !== null && start !== void 0 ? start : 0, (end !== null && end !== void 0 ? end : array.length - 1) + 1)
|
|
30
84
|
: array;
|
|
31
85
|
return source.toReversed();
|
|
32
86
|
}
|
|
33
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Internal helper to create a reversed copy using manual iteration (legacy fallback).
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
34
91
|
function _reverseOld(array, start, end) {
|
|
35
92
|
var _start = start !== null && start !== void 0 ? start : 0;
|
|
36
93
|
var _end = end !== null && end !== void 0 ? end : array.length - 1;
|
|
@@ -42,10 +99,23 @@ function _reverseOld(array, start, end) {
|
|
|
42
99
|
res[resIndex--] = array[arrayIndex];
|
|
43
100
|
return res;
|
|
44
101
|
}
|
|
45
|
-
|
|
46
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Returns a copy of the array (or a slice) with elements in reversed order.
|
|
104
|
+
* @typeparam T - array element type
|
|
105
|
+
* @param array - the source array
|
|
106
|
+
* @param start - optional start index (inclusive)
|
|
107
|
+
* @param end - optional end index (inclusive)
|
|
108
|
+
*/
|
|
47
109
|
exports.reverse = 'toReversed' in Array.prototype ? _reverseNew : _reverseOld;
|
|
48
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Performs the given function for each element of the array, optionally in reverse order.
|
|
112
|
+
* Halting is supported through the provided `TraverseState`.
|
|
113
|
+
* @typeparam T - element type
|
|
114
|
+
* @param array - the source array
|
|
115
|
+
* @param f - callback receiving (value, sequential index, halt)
|
|
116
|
+
* @param state - traversal state (created if omitted)
|
|
117
|
+
* @param reversed - whether to traverse in reverse order
|
|
118
|
+
*/
|
|
49
119
|
function forEach(array, f, state, reversed) {
|
|
50
120
|
if (state === void 0) { state = (0, common_1.TraverseState)(); }
|
|
51
121
|
if (reversed === void 0) { reversed = false; }
|
|
@@ -66,8 +136,15 @@ function forEach(array, f, state, reversed) {
|
|
|
66
136
|
}
|
|
67
137
|
}
|
|
68
138
|
}
|
|
69
|
-
|
|
70
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Returns a copy of the array where the given function is applied to each element.
|
|
141
|
+
* Supports an index offset useful for composed traversals.
|
|
142
|
+
* @typeparam T - source element type
|
|
143
|
+
* @typeparam R - result element type
|
|
144
|
+
* @param array - the source array
|
|
145
|
+
* @param f - the mapping function
|
|
146
|
+
* @param indexOffset - optional start index value passed to `f`
|
|
147
|
+
*/
|
|
71
148
|
function map(array, f, indexOffset) {
|
|
72
149
|
if (indexOffset === void 0) { indexOffset = 0; }
|
|
73
150
|
if (indexOffset === 0) {
|
|
@@ -83,8 +160,14 @@ function map(array, f, indexOffset) {
|
|
|
83
160
|
}
|
|
84
161
|
return result;
|
|
85
162
|
}
|
|
86
|
-
|
|
87
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Returns a copy of the array where the given function is applied to each element in reverse order.
|
|
165
|
+
* @typeparam T - source element type
|
|
166
|
+
* @typeparam R - result element type
|
|
167
|
+
* @param array - the source array
|
|
168
|
+
* @param f - the mapping function
|
|
169
|
+
* @param indexOffset - optional index offset passed to `f`
|
|
170
|
+
*/
|
|
88
171
|
function reverseMap(array, f, indexOffset) {
|
|
89
172
|
if (indexOffset === void 0) { indexOffset = 0; }
|
|
90
173
|
var result = [];
|
|
@@ -95,29 +178,53 @@ function reverseMap(array, f, indexOffset) {
|
|
|
95
178
|
result[resultIndex++] = f(array[arrayIndex], index++);
|
|
96
179
|
return result;
|
|
97
180
|
}
|
|
98
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Internal helper to prepend a value using `toSpliced`.
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
99
185
|
function _prependNew(array, value) {
|
|
100
186
|
return array.toSpliced(0, 0, value);
|
|
101
187
|
}
|
|
102
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Internal helper to prepend a value using legacy cloning.
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
103
192
|
function _prependOld(array, value) {
|
|
104
193
|
var clone = array.slice();
|
|
105
194
|
clone.unshift(value);
|
|
106
195
|
return clone;
|
|
107
196
|
}
|
|
108
|
-
|
|
109
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Returns a copy of the array with the given value inserted at the start.
|
|
199
|
+
* @typeparam T - element type
|
|
200
|
+
* @param array - the source array
|
|
201
|
+
* @param value - value to insert at index 0
|
|
202
|
+
*/
|
|
110
203
|
exports.prepend = "toSpliced" in Array.prototype ? _prependNew : _prependOld;
|
|
204
|
+
/**
|
|
205
|
+
* Internal helper to obtain the last element using modern `at`.
|
|
206
|
+
* @internal
|
|
207
|
+
*/
|
|
111
208
|
function _lastNew(arr) {
|
|
112
209
|
return arr.at(-1);
|
|
113
210
|
}
|
|
114
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Internal helper to obtain the last element using index arithmetic.
|
|
213
|
+
* @internal
|
|
214
|
+
*/
|
|
115
215
|
function _lastOld(arr) {
|
|
116
216
|
return arr[arr.length - 1];
|
|
117
217
|
}
|
|
118
|
-
|
|
119
|
-
|
|
218
|
+
/**
|
|
219
|
+
* Returns the last element of the array.
|
|
220
|
+
* @typeparam T - element type
|
|
221
|
+
* @param arr - the array
|
|
222
|
+
*/
|
|
120
223
|
exports.last = "at" in Array.prototype ? _lastNew : _lastOld;
|
|
224
|
+
/**
|
|
225
|
+
* Internal helper implementing an immutable index update via `with`.
|
|
226
|
+
* @internal
|
|
227
|
+
*/
|
|
121
228
|
function _updateNew(arr, index, updater) {
|
|
122
229
|
if (index < 0 || index >= arr.length) {
|
|
123
230
|
return arr;
|
|
@@ -129,7 +236,10 @@ function _updateNew(arr, index, updater) {
|
|
|
129
236
|
}
|
|
130
237
|
return arr.with(index, newValue);
|
|
131
238
|
}
|
|
132
|
-
|
|
239
|
+
/**
|
|
240
|
+
* Internal helper implementing an immutable index update via cloning.
|
|
241
|
+
* @internal
|
|
242
|
+
*/
|
|
133
243
|
function _updateOld(arr, index, updater) {
|
|
134
244
|
if (index < 0 || index >= arr.length) {
|
|
135
245
|
return arr;
|
|
@@ -143,10 +253,19 @@ function _updateOld(arr, index, updater) {
|
|
|
143
253
|
newArr[index] = newValue;
|
|
144
254
|
return newArr;
|
|
145
255
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
256
|
+
/**
|
|
257
|
+
* Returns a copy of the array where the element at the given index is replaced using the provided updater.
|
|
258
|
+
* If the result value is identical (by `Object.is`) the original array is returned.
|
|
259
|
+
* @typeparam T - element type
|
|
260
|
+
* @param arr - the source array
|
|
261
|
+
* @param index - the index to update
|
|
262
|
+
* @param updater - value or function update description
|
|
263
|
+
*/
|
|
149
264
|
exports.update = "with" in Array.prototype ? _updateNew : _updateOld;
|
|
265
|
+
/**
|
|
266
|
+
* Internal helper applying a modifier function via `with`.
|
|
267
|
+
* @internal
|
|
268
|
+
*/
|
|
150
269
|
function _modNew(arr, index, f) {
|
|
151
270
|
if (index < 0 || index >= arr.length) {
|
|
152
271
|
return arr;
|
|
@@ -158,7 +277,10 @@ function _modNew(arr, index, f) {
|
|
|
158
277
|
}
|
|
159
278
|
return arr.with(index, newValue);
|
|
160
279
|
}
|
|
161
|
-
|
|
280
|
+
/**
|
|
281
|
+
* Internal helper applying a modifier function via cloning.
|
|
282
|
+
* @internal
|
|
283
|
+
*/
|
|
162
284
|
function _modOld(arr, index, f) {
|
|
163
285
|
if (index < 0 || index >= arr.length) {
|
|
164
286
|
return arr;
|
|
@@ -172,32 +294,59 @@ function _modOld(arr, index, f) {
|
|
|
172
294
|
newArr[index] = newValue;
|
|
173
295
|
return newArr;
|
|
174
296
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
297
|
+
/**
|
|
298
|
+
* Returns a copy of the array where the element at the given index is transformed by a modifier function.
|
|
299
|
+
* If the result value is identical (by `Object.is`) the original array is returned.
|
|
300
|
+
* @typeparam T - element type
|
|
301
|
+
* @param arr - the source array
|
|
302
|
+
* @param index - the index to modify
|
|
303
|
+
* @param f - modifier function receiving the current value
|
|
304
|
+
*/
|
|
178
305
|
exports.mod = "with" in Array.prototype ? _modNew : _modOld;
|
|
306
|
+
/**
|
|
307
|
+
* Internal helper for inserting a value using `toSpliced`.
|
|
308
|
+
* @internal
|
|
309
|
+
*/
|
|
179
310
|
function _insertNew(arr, index, value) {
|
|
180
311
|
return arr.toSpliced(index, 0, value);
|
|
181
312
|
}
|
|
182
|
-
|
|
313
|
+
/**
|
|
314
|
+
* Internal helper for inserting a value using legacy `splice` on a clone.
|
|
315
|
+
* @internal
|
|
316
|
+
*/
|
|
183
317
|
function _insertOld(arr, index, value) {
|
|
184
318
|
var clone = arr.slice();
|
|
185
319
|
clone.splice(index, 0, value);
|
|
186
320
|
return clone;
|
|
187
321
|
}
|
|
188
|
-
|
|
189
|
-
|
|
322
|
+
/**
|
|
323
|
+
* Returns a copy of the array where at the given index the provided value is inserted.
|
|
324
|
+
* @typeparam T - element type
|
|
325
|
+
* @param arr - the source array
|
|
326
|
+
* @param index - insertion index
|
|
327
|
+
* @param value - value to insert
|
|
328
|
+
*/
|
|
190
329
|
exports.insert = "toSpliced" in Array.prototype ? _insertNew : _insertOld;
|
|
191
|
-
|
|
330
|
+
/**
|
|
331
|
+
* Returns a copy of the array without its first element.
|
|
332
|
+
* @typeparam T - element type
|
|
333
|
+
* @param arr - the source array
|
|
334
|
+
*/
|
|
192
335
|
function tail(arr) {
|
|
193
336
|
return arr.slice(1);
|
|
194
337
|
}
|
|
195
|
-
|
|
196
|
-
|
|
338
|
+
/**
|
|
339
|
+
* Returns a copy of the array without its last element.
|
|
340
|
+
* @typeparam T - element type
|
|
341
|
+
* @param arr - the source array
|
|
342
|
+
*/
|
|
197
343
|
function init(arr) {
|
|
198
344
|
return arr.slice(0, arr.length - 1);
|
|
199
345
|
}
|
|
200
|
-
|
|
346
|
+
/**
|
|
347
|
+
* Internal helper providing an immutable `splice` using `toSpliced`.
|
|
348
|
+
* @internal
|
|
349
|
+
*/
|
|
201
350
|
function _spliceNew(arr, start, deleteCount) {
|
|
202
351
|
var items = [];
|
|
203
352
|
for (var _i = 3; _i < arguments.length; _i++) {
|
|
@@ -205,7 +354,10 @@ function _spliceNew(arr, start, deleteCount) {
|
|
|
205
354
|
}
|
|
206
355
|
return arr.toSpliced.apply(arr, tslib_1.__spreadArray([start, deleteCount], tslib_1.__read(items), false));
|
|
207
356
|
}
|
|
208
|
-
|
|
357
|
+
/**
|
|
358
|
+
* Internal helper providing an immutable `splice` via cloning.
|
|
359
|
+
* @internal
|
|
360
|
+
*/
|
|
209
361
|
function _spliceOld(arr, start, deleteCount) {
|
|
210
362
|
var items = [];
|
|
211
363
|
for (var _i = 3; _i < arguments.length; _i++) {
|
|
@@ -215,10 +367,20 @@ function _spliceOld(arr, start, deleteCount) {
|
|
|
215
367
|
clone.splice.apply(clone, tslib_1.__spreadArray([start, deleteCount], tslib_1.__read(items), false));
|
|
216
368
|
return clone;
|
|
217
369
|
}
|
|
218
|
-
|
|
219
|
-
|
|
370
|
+
/**
|
|
371
|
+
* Immutable version of the array `.splice` command, always returning a new array.
|
|
372
|
+
* @typeparam T - element type
|
|
373
|
+
* @param arr - the source array
|
|
374
|
+
* @param start - start index
|
|
375
|
+
* @param deleteCount - number of elements to delete
|
|
376
|
+
* @param items - optional items to insert
|
|
377
|
+
*/
|
|
220
378
|
exports.splice = "toSpliced" in Array.prototype ? _spliceNew : _spliceOld;
|
|
221
|
-
|
|
379
|
+
/**
|
|
380
|
+
* Returns a copy of a (potentially) sparse array preserving sparsity (skips holes).
|
|
381
|
+
* @typeparam T - element type
|
|
382
|
+
* @param arr - the source sparse array
|
|
383
|
+
*/
|
|
222
384
|
function copySparse(arr) {
|
|
223
385
|
var clone = [];
|
|
224
386
|
for (var key in arr) {
|
|
@@ -226,9 +388,13 @@ function copySparse(arr) {
|
|
|
226
388
|
}
|
|
227
389
|
return clone;
|
|
228
390
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
391
|
+
/**
|
|
392
|
+
* Returns a copy of a sparse array applying the given function to each present element, preserving holes.
|
|
393
|
+
* @typeparam T - source element type
|
|
394
|
+
* @typeparam T2 - result element type
|
|
395
|
+
* @param arr - the source sparse array
|
|
396
|
+
* @param f - mapping function
|
|
397
|
+
*/
|
|
232
398
|
function mapSparse(arr, f) {
|
|
233
399
|
var result = Array(arr.length);
|
|
234
400
|
for (var key in arr) {
|
|
@@ -236,5 +402,4 @@ function mapSparse(arr, f) {
|
|
|
236
402
|
}
|
|
237
403
|
return result;
|
|
238
404
|
}
|
|
239
|
-
exports.mapSparse = mapSparse;
|
|
240
405
|
//# sourceMappingURL=arr.cjs.map
|
package/dist/cjs/arr.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arr.cjs","sourceRoot":"","sources":["../../_cjs_prepare/arr.cts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"arr.cjs","sourceRoot":"","sources":["../../_cjs_prepare/arr.cts"],"names":[],"mappings":";;;AAUA,gCAEC;AAUD,gCAIC;AAmBD,wBAOC;AAMD,kCAWC;AAMD,kCAgBC;AAqBD,0BAwBC;AAWD,kBAmBC;AAUD,gCAcC;AAMD,kCAKC;AAMD,kCAOC;AAeD,4BAEC;AAMD,4BAEC;AAaD,gCAgBC;AAMD,gCAkBC;AAgBD,0BAiBC;AAMD,0BAmBC;AAgBD,gCAEC;AAMD,gCAIC;AAgBD,oBAEC;AAOD,oBAEC;A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