@bemoje/iter 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/filterArray.cjs +18 -0
- package/lib/filterArray.d.cts +18 -0
- package/lib/filterArray.d.ts +18 -0
- package/lib/filterArray.js +16 -0
- package/lib/filterIterable.cjs +14 -0
- package/lib/filterIterable.d.cts +18 -0
- package/lib/filterIterable.d.ts +18 -0
- package/lib/filterIterable.js +11 -0
- package/lib/filterIterableEntries.cjs +12 -0
- package/lib/filterIterableEntries.d.cts +18 -0
- package/lib/filterIterableEntries.d.ts +18 -0
- package/lib/filterIterableEntries.js +9 -0
- package/lib/filterIterableKeys.cjs +14 -0
- package/lib/filterIterableKeys.d.cts +18 -0
- package/lib/filterIterableKeys.d.ts +18 -0
- package/lib/filterIterableKeys.js +11 -0
- package/lib/filterIterableValues.cjs +14 -0
- package/lib/filterIterableValues.d.cts +18 -0
- package/lib/filterIterableValues.d.ts +18 -0
- package/lib/filterIterableValues.js +11 -0
- package/lib/filterMap.cjs +16 -0
- package/lib/filterMap.d.cts +18 -0
- package/lib/filterMap.d.ts +18 -0
- package/lib/filterMap.js +14 -0
- package/lib/filterObject.cjs +18 -0
- package/lib/filterObject.d.cts +18 -0
- package/lib/filterObject.d.ts +18 -0
- package/lib/filterObject.js +15 -0
- package/lib/filterSet.cjs +16 -0
- package/lib/filterSet.d.cts +18 -0
- package/lib/filterSet.d.ts +18 -0
- package/lib/filterSet.js +14 -0
- package/lib/forEachArray.cjs +14 -0
- package/lib/forEachArray.d.cts +17 -0
- package/lib/forEachArray.d.ts +17 -0
- package/lib/forEachArray.js +12 -0
- package/lib/forEachIterable.cjs +14 -0
- package/lib/forEachIterable.d.cts +17 -0
- package/lib/forEachIterable.d.ts +17 -0
- package/lib/forEachIterable.js +11 -0
- package/lib/forEachIterableEntries.cjs +14 -0
- package/lib/forEachIterableEntries.d.cts +6 -0
- package/lib/forEachIterableEntries.d.ts +6 -0
- package/lib/forEachIterableEntries.js +11 -0
- package/lib/forEachIterableKeys.cjs +14 -0
- package/lib/forEachIterableKeys.d.cts +17 -0
- package/lib/forEachIterableKeys.d.ts +17 -0
- package/lib/forEachIterableKeys.js +11 -0
- package/lib/forEachIterableValues.cjs +14 -0
- package/lib/forEachIterableValues.d.cts +17 -0
- package/lib/forEachIterableValues.d.ts +17 -0
- package/lib/forEachIterableValues.js +11 -0
- package/lib/forEachMap.cjs +12 -0
- package/lib/forEachMap.d.cts +17 -0
- package/lib/forEachMap.d.ts +17 -0
- package/lib/forEachMap.js +10 -0
- package/lib/forEachObject.cjs +14 -0
- package/lib/forEachObject.d.cts +17 -0
- package/lib/forEachObject.d.ts +17 -0
- package/lib/forEachObject.js +11 -0
- package/lib/forEachSet.cjs +12 -0
- package/lib/forEachSet.d.cts +17 -0
- package/lib/forEachSet.d.ts +17 -0
- package/lib/forEachSet.js +10 -0
- package/lib/index.cjs +236 -0
- package/lib/index.d.cts +33 -0
- package/lib/index.d.ts +33 -0
- package/lib/index.js +33 -0
- package/lib/mapArray.cjs +16 -0
- package/lib/mapArray.d.cts +17 -0
- package/lib/mapArray.d.ts +17 -0
- package/lib/mapArray.js +14 -0
- package/lib/mapIterable.cjs +14 -0
- package/lib/mapIterable.d.cts +17 -0
- package/lib/mapIterable.d.ts +17 -0
- package/lib/mapIterable.js +11 -0
- package/lib/mapIterableEntries.cjs +12 -0
- package/lib/mapIterableEntries.d.cts +17 -0
- package/lib/mapIterableEntries.d.ts +17 -0
- package/lib/mapIterableEntries.js +9 -0
- package/lib/mapIterableKeys.cjs +17 -0
- package/lib/mapIterableKeys.d.cts +17 -0
- package/lib/mapIterableKeys.d.ts +17 -0
- package/lib/mapIterableKeys.js +14 -0
- package/lib/mapIterableValues.cjs +17 -0
- package/lib/mapIterableValues.d.cts +17 -0
- package/lib/mapIterableValues.d.ts +17 -0
- package/lib/mapIterableValues.js +14 -0
- package/lib/mapMap.cjs +14 -0
- package/lib/mapMap.d.cts +17 -0
- package/lib/mapMap.d.ts +17 -0
- package/lib/mapMap.js +12 -0
- package/lib/mapObject.cjs +16 -0
- package/lib/mapObject.d.cts +17 -0
- package/lib/mapObject.d.ts +17 -0
- package/lib/mapObject.js +13 -0
- package/lib/mapSet.cjs +14 -0
- package/lib/mapSet.d.cts +17 -0
- package/lib/mapSet.d.ts +17 -0
- package/lib/mapSet.js +12 -0
- package/lib/reduceArray.cjs +16 -0
- package/lib/reduceArray.d.cts +18 -0
- package/lib/reduceArray.d.ts +18 -0
- package/lib/reduceArray.js +14 -0
- package/lib/reduceIterable.cjs +14 -0
- package/lib/reduceIterable.d.cts +18 -0
- package/lib/reduceIterable.d.ts +18 -0
- package/lib/reduceIterable.js +12 -0
- package/lib/reduceIterableEntries.cjs +14 -0
- package/lib/reduceIterableEntries.d.cts +18 -0
- package/lib/reduceIterableEntries.d.ts +18 -0
- package/lib/reduceIterableEntries.js +12 -0
- package/lib/reduceIterableKeys.cjs +14 -0
- package/lib/reduceIterableKeys.d.cts +18 -0
- package/lib/reduceIterableKeys.d.ts +18 -0
- package/lib/reduceIterableKeys.js +12 -0
- package/lib/reduceIterableValues.cjs +14 -0
- package/lib/reduceIterableValues.d.cts +18 -0
- package/lib/reduceIterableValues.d.ts +18 -0
- package/lib/reduceIterableValues.js +12 -0
- package/lib/reduceMap.cjs +14 -0
- package/lib/reduceMap.d.cts +18 -0
- package/lib/reduceMap.d.ts +18 -0
- package/lib/reduceMap.js +12 -0
- package/lib/reduceObject.cjs +16 -0
- package/lib/reduceObject.d.cts +18 -0
- package/lib/reduceObject.d.ts +18 -0
- package/lib/reduceObject.js +13 -0
- package/lib/reduceSet.cjs +14 -0
- package/lib/reduceSet.d.cts +18 -0
- package/lib/reduceSet.d.ts +18 -0
- package/lib/reduceSet.js +12 -0
- package/lib/toObjectIterable.cjs +18 -0
- package/lib/toObjectIterable.d.cts +7 -0
- package/lib/toObjectIterable.d.ts +7 -0
- package/lib/toObjectIterable.js +16 -0
- package/package.json +501 -25
- package/index.d.ts +0 -524
- package/index.mjs +0 -295
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an array to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param array - The array to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
12
|
+
* const sum = reduceArray(numbers, (acc, n) => acc + n, 0)
|
|
13
|
+
* // sum: 15
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceArray<V, R>(array: readonly V[], reducer: (accumulator: R, value: V, index: number) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceArray };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an array to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param array - The array to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
12
|
+
* const sum = reduceArray(numbers, (acc, n) => acc + n, 0)
|
|
13
|
+
* // sum: 15
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceArray<V, R>(array: readonly V[], reducer: (accumulator: R, value: V, index: number) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceArray };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
function reduceArray(array, reducer, initial) {
|
|
4
|
+
let accumulator = initial;
|
|
5
|
+
let index = 0;
|
|
6
|
+
for (const value of array) {
|
|
7
|
+
accumulator = reducer(accumulator, value, index);
|
|
8
|
+
index++;
|
|
9
|
+
}
|
|
10
|
+
return accumulator;
|
|
11
|
+
}
|
|
12
|
+
__name(reduceArray, "reduceArray");
|
|
13
|
+
|
|
14
|
+
export { reduceArray };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function reduceIterable(collection, reducer, initial) {
|
|
6
|
+
let accumulator = initial;
|
|
7
|
+
for (const value of collection) {
|
|
8
|
+
accumulator = reducer(accumulator, value);
|
|
9
|
+
}
|
|
10
|
+
return accumulator;
|
|
11
|
+
}
|
|
12
|
+
__name(reduceIterable, "reduceIterable");
|
|
13
|
+
|
|
14
|
+
exports.reduceIterable = reduceIterable;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an iterable to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param collection - The iterable to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
12
|
+
* const sum = reduceIterable(numbers, (acc, n) => acc + n, 0)
|
|
13
|
+
* // sum: 15
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceIterable<T, R>(collection: Iterable<T>, reducer: (accumulator: R, value: T) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceIterable };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an iterable to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param collection - The iterable to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
12
|
+
* const sum = reduceIterable(numbers, (acc, n) => acc + n, 0)
|
|
13
|
+
* // sum: 15
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceIterable<T, R>(collection: Iterable<T>, reducer: (accumulator: R, value: T) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceIterable };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
function reduceIterable(collection, reducer, initial) {
|
|
4
|
+
let accumulator = initial;
|
|
5
|
+
for (const value of collection) {
|
|
6
|
+
accumulator = reducer(accumulator, value);
|
|
7
|
+
}
|
|
8
|
+
return accumulator;
|
|
9
|
+
}
|
|
10
|
+
__name(reduceIterable, "reduceIterable");
|
|
11
|
+
|
|
12
|
+
export { reduceIterable };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function reduceIterableEntries(mapLike, reducer, initial) {
|
|
6
|
+
let accumulator = initial;
|
|
7
|
+
for (const entry of mapLike) {
|
|
8
|
+
accumulator = reducer(accumulator, entry);
|
|
9
|
+
}
|
|
10
|
+
return accumulator;
|
|
11
|
+
}
|
|
12
|
+
__name(reduceIterableEntries, "reduceIterableEntries");
|
|
13
|
+
|
|
14
|
+
exports.reduceIterableEntries = reduceIterableEntries;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an iterable of key-value entries to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param mapLike - An iterable of key-value tuples to reduce
|
|
5
|
+
* @param reducer - A function that combines entries
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const entries: [string, number][] = [['a', 1], ['b', 2], ['c', 3]]
|
|
12
|
+
* const sum = reduceIterableEntries(entries, (acc, [key, value]) => acc + value, 0)
|
|
13
|
+
* // sum: 6
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceIterableEntries<K, V, R>(mapLike: Iterable<[K, V]>, reducer: (accumulator: R, entry: [K, V]) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceIterableEntries };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an iterable of key-value entries to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param mapLike - An iterable of key-value tuples to reduce
|
|
5
|
+
* @param reducer - A function that combines entries
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const entries: [string, number][] = [['a', 1], ['b', 2], ['c', 3]]
|
|
12
|
+
* const sum = reduceIterableEntries(entries, (acc, [key, value]) => acc + value, 0)
|
|
13
|
+
* // sum: 6
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceIterableEntries<K, V, R>(mapLike: Iterable<[K, V]>, reducer: (accumulator: R, entry: [K, V]) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceIterableEntries };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
function reduceIterableEntries(mapLike, reducer, initial) {
|
|
4
|
+
let accumulator = initial;
|
|
5
|
+
for (const entry of mapLike) {
|
|
6
|
+
accumulator = reducer(accumulator, entry);
|
|
7
|
+
}
|
|
8
|
+
return accumulator;
|
|
9
|
+
}
|
|
10
|
+
__name(reduceIterableEntries, "reduceIterableEntries");
|
|
11
|
+
|
|
12
|
+
export { reduceIterableEntries };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function reduceIterableKeys(mapLike, reducer, initial) {
|
|
6
|
+
let accumulator = initial;
|
|
7
|
+
for (const [k, v] of mapLike) {
|
|
8
|
+
accumulator = reducer(accumulator, k, v);
|
|
9
|
+
}
|
|
10
|
+
return accumulator;
|
|
11
|
+
}
|
|
12
|
+
__name(reduceIterableKeys, "reduceIterableKeys");
|
|
13
|
+
|
|
14
|
+
exports.reduceIterableKeys = reduceIterableKeys;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an iterable of key-value entries based on keys using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param mapLike - An iterable of key-value tuples to reduce
|
|
5
|
+
* @param reducer - A function that combines keys
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const entries: [string, number][] = [['a', 1], ['b', 2], ['c', 3]]
|
|
12
|
+
* const keys = reduceIterableKeys(entries, (acc, key, value) => acc + key, '')
|
|
13
|
+
* // keys: 'abc'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceIterableKeys<K, V, R>(mapLike: Iterable<[K, V]>, reducer: (accumulator: R, key: K, value: V) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceIterableKeys };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an iterable of key-value entries based on keys using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param mapLike - An iterable of key-value tuples to reduce
|
|
5
|
+
* @param reducer - A function that combines keys
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const entries: [string, number][] = [['a', 1], ['b', 2], ['c', 3]]
|
|
12
|
+
* const keys = reduceIterableKeys(entries, (acc, key, value) => acc + key, '')
|
|
13
|
+
* // keys: 'abc'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceIterableKeys<K, V, R>(mapLike: Iterable<[K, V]>, reducer: (accumulator: R, key: K, value: V) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceIterableKeys };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
function reduceIterableKeys(mapLike, reducer, initial) {
|
|
4
|
+
let accumulator = initial;
|
|
5
|
+
for (const [k, v] of mapLike) {
|
|
6
|
+
accumulator = reducer(accumulator, k, v);
|
|
7
|
+
}
|
|
8
|
+
return accumulator;
|
|
9
|
+
}
|
|
10
|
+
__name(reduceIterableKeys, "reduceIterableKeys");
|
|
11
|
+
|
|
12
|
+
export { reduceIterableKeys };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function reduceIterableValues(mapLike, reducer, initial) {
|
|
6
|
+
let accumulator = initial;
|
|
7
|
+
for (const [k, v] of mapLike) {
|
|
8
|
+
accumulator = reducer(accumulator, v, k);
|
|
9
|
+
}
|
|
10
|
+
return accumulator;
|
|
11
|
+
}
|
|
12
|
+
__name(reduceIterableValues, "reduceIterableValues");
|
|
13
|
+
|
|
14
|
+
exports.reduceIterableValues = reduceIterableValues;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an iterable of key-value entries based on values using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param mapLike - An iterable of key-value tuples to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const entries: [string, number][] = [['a', 1], ['b', 2], ['c', 3]]
|
|
12
|
+
* const sum = reduceIterableValues(entries, (acc, value, key) => acc + value, 0)
|
|
13
|
+
* // sum: 6
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceIterableValues<K, V, R>(mapLike: Iterable<[K, V]>, reducer: (accumulator: R, value: V, key: K) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceIterableValues };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an iterable of key-value entries based on values using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param mapLike - An iterable of key-value tuples to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const entries: [string, number][] = [['a', 1], ['b', 2], ['c', 3]]
|
|
12
|
+
* const sum = reduceIterableValues(entries, (acc, value, key) => acc + value, 0)
|
|
13
|
+
* // sum: 6
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceIterableValues<K, V, R>(mapLike: Iterable<[K, V]>, reducer: (accumulator: R, value: V, key: K) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceIterableValues };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
function reduceIterableValues(mapLike, reducer, initial) {
|
|
4
|
+
let accumulator = initial;
|
|
5
|
+
for (const [k, v] of mapLike) {
|
|
6
|
+
accumulator = reducer(accumulator, v, k);
|
|
7
|
+
}
|
|
8
|
+
return accumulator;
|
|
9
|
+
}
|
|
10
|
+
__name(reduceIterableValues, "reduceIterableValues");
|
|
11
|
+
|
|
12
|
+
export { reduceIterableValues };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function reduceMap(map, reducer, initial) {
|
|
6
|
+
let accumulator = initial;
|
|
7
|
+
for (const [key, value] of map) {
|
|
8
|
+
accumulator = reducer(accumulator, value, key);
|
|
9
|
+
}
|
|
10
|
+
return accumulator;
|
|
11
|
+
}
|
|
12
|
+
__name(reduceMap, "reduceMap");
|
|
13
|
+
|
|
14
|
+
exports.reduceMap = reduceMap;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce a Map to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param map - The Map to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const map = new Map([['a', 1], ['b', 2], ['c', 3]])
|
|
12
|
+
* const sum = reduceMap(map, (acc, value, key) => acc + value, 0)
|
|
13
|
+
* // sum: 6
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceMap<K, V, R>(map: ReadonlyMap<K, V>, reducer: (accumulator: R, value: V, key: K) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceMap };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce a Map to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param map - The Map to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const map = new Map([['a', 1], ['b', 2], ['c', 3]])
|
|
12
|
+
* const sum = reduceMap(map, (acc, value, key) => acc + value, 0)
|
|
13
|
+
* // sum: 6
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceMap<K, V, R>(map: ReadonlyMap<K, V>, reducer: (accumulator: R, value: V, key: K) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceMap };
|
package/lib/reduceMap.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
function reduceMap(map, reducer, initial) {
|
|
4
|
+
let accumulator = initial;
|
|
5
|
+
for (const [key, value] of map) {
|
|
6
|
+
accumulator = reducer(accumulator, value, key);
|
|
7
|
+
}
|
|
8
|
+
return accumulator;
|
|
9
|
+
}
|
|
10
|
+
__name(reduceMap, "reduceMap");
|
|
11
|
+
|
|
12
|
+
export { reduceMap };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var entriesOf = require('@mono/object/entriesOf');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
function reduceObject(object, reducer, initial) {
|
|
8
|
+
let accumulator = initial;
|
|
9
|
+
for (const [key, value] of entriesOf.entriesOf(object)) {
|
|
10
|
+
accumulator = reducer(accumulator, value, key);
|
|
11
|
+
}
|
|
12
|
+
return accumulator;
|
|
13
|
+
}
|
|
14
|
+
__name(reduceObject, "reduceObject");
|
|
15
|
+
|
|
16
|
+
exports.reduceObject = reduceObject;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an object to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param object - The object to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const obj = { a: 1, b: 2, c: 3 }
|
|
12
|
+
* const sum = reduceObject(obj, (acc, value, key) => acc + value, 0)
|
|
13
|
+
* // sum: 6
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceObject<T extends Record<string, unknown>, R>(object: T, reducer: (accumulator: R, value: T[keyof T], key: keyof T) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceObject };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an object to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param object - The object to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const obj = { a: 1, b: 2, c: 3 }
|
|
12
|
+
* const sum = reduceObject(obj, (acc, value, key) => acc + value, 0)
|
|
13
|
+
* // sum: 6
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceObject<T extends Record<string, unknown>, R>(object: T, reducer: (accumulator: R, value: T[keyof T], key: keyof T) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceObject };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
import { entriesOf } from '@mono/object/entriesOf';
|
|
3
|
+
|
|
4
|
+
function reduceObject(object, reducer, initial) {
|
|
5
|
+
let accumulator = initial;
|
|
6
|
+
for (const [key, value] of entriesOf(object)) {
|
|
7
|
+
accumulator = reducer(accumulator, value, key);
|
|
8
|
+
}
|
|
9
|
+
return accumulator;
|
|
10
|
+
}
|
|
11
|
+
__name(reduceObject, "reduceObject");
|
|
12
|
+
|
|
13
|
+
export { reduceObject };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function reduceSet(set, reducer, initial) {
|
|
6
|
+
let accumulator = initial;
|
|
7
|
+
for (const value of set) {
|
|
8
|
+
accumulator = reducer(accumulator, value);
|
|
9
|
+
}
|
|
10
|
+
return accumulator;
|
|
11
|
+
}
|
|
12
|
+
__name(reduceSet, "reduceSet");
|
|
13
|
+
|
|
14
|
+
exports.reduceSet = reduceSet;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce a Set to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param set - The Set to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const set = new Set([1, 2, 3, 4, 5])
|
|
12
|
+
* const sum = reduceSet(set, (acc, n) => acc + n, 0)
|
|
13
|
+
* // sum: 15
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceSet<V, R>(set: ReadonlySet<V>, reducer: (accumulator: R, value: V) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceSet };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce a Set to a single value using a reducer function.
|
|
3
|
+
*
|
|
4
|
+
* @param set - The Set to reduce
|
|
5
|
+
* @param reducer - A function that combines values
|
|
6
|
+
* @param initial - The initial value for the reduction
|
|
7
|
+
* @returns The reduced value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const set = new Set([1, 2, 3, 4, 5])
|
|
12
|
+
* const sum = reduceSet(set, (acc, n) => acc + n, 0)
|
|
13
|
+
* // sum: 15
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function reduceSet<V, R>(set: ReadonlySet<V>, reducer: (accumulator: R, value: V) => R, initial: R): R;
|
|
17
|
+
|
|
18
|
+
export { reduceSet };
|
package/lib/reduceSet.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
function reduceSet(set, reducer, initial) {
|
|
4
|
+
let accumulator = initial;
|
|
5
|
+
for (const value of set) {
|
|
6
|
+
accumulator = reducer(accumulator, value);
|
|
7
|
+
}
|
|
8
|
+
return accumulator;
|
|
9
|
+
}
|
|
10
|
+
__name(reduceSet, "reduceSet");
|
|
11
|
+
|
|
12
|
+
export { reduceSet };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function toObjectIterable(mapLike) {
|
|
6
|
+
const object = {};
|
|
7
|
+
for (const [key, value] of mapLike) {
|
|
8
|
+
if (typeof key !== "string" && typeof key !== "number" && typeof key !== "symbol") {
|
|
9
|
+
object[String(key)] = value;
|
|
10
|
+
} else {
|
|
11
|
+
object[key] = value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return object;
|
|
15
|
+
}
|
|
16
|
+
__name(toObjectIterable, "toObjectIterable");
|
|
17
|
+
|
|
18
|
+
exports.toObjectIterable = toObjectIterable;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a map-like iterable to a regular object.
|
|
3
|
+
*/
|
|
4
|
+
declare function toObjectIterable<K extends string, V>(mapLike: Iterable<[K, V]>): Record<K, V>;
|
|
5
|
+
declare function toObjectIterable<K, V>(mapLike: Iterable<[K, V]>): Record<Extract<K, string> | string, V>;
|
|
6
|
+
|
|
7
|
+
export { toObjectIterable };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a map-like iterable to a regular object.
|
|
3
|
+
*/
|
|
4
|
+
declare function toObjectIterable<K extends string, V>(mapLike: Iterable<[K, V]>): Record<K, V>;
|
|
5
|
+
declare function toObjectIterable<K, V>(mapLike: Iterable<[K, V]>): Record<Extract<K, string> | string, V>;
|
|
6
|
+
|
|
7
|
+
export { toObjectIterable };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
function toObjectIterable(mapLike) {
|
|
4
|
+
const object = {};
|
|
5
|
+
for (const [key, value] of mapLike) {
|
|
6
|
+
if (typeof key !== "string" && typeof key !== "number" && typeof key !== "symbol") {
|
|
7
|
+
object[String(key)] = value;
|
|
8
|
+
} else {
|
|
9
|
+
object[key] = value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return object;
|
|
13
|
+
}
|
|
14
|
+
__name(toObjectIterable, "toObjectIterable");
|
|
15
|
+
|
|
16
|
+
export { toObjectIterable };
|