@develia/commons 0.4.23 → 0.4.25
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/array.d.ts.map +1 -0
- package/dist/array.js.map +1 -0
- package/dist/async-pool-executor.d.ts.map +1 -0
- package/dist/async-pool-executor.js.map +1 -0
- package/dist/browser/form-utilities.d.ts.map +1 -0
- package/dist/browser/form-utilities.js.map +1 -0
- package/dist/browser/geo-location.d.ts.map +1 -0
- package/dist/browser/geo-location.js.map +1 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/native-bridge.d.ts.map +1 -0
- package/dist/browser/native-bridge.js.map +1 -0
- package/dist/cancellable-promise.d.ts.map +1 -0
- package/dist/cancellable-promise.js.map +1 -0
- package/dist/clean-url-search-params.d.ts.map +1 -0
- package/dist/clean-url-search-params.js.map +1 -0
- package/dist/collections/cache-dictionary.d.ts.map +1 -0
- package/dist/collections/cache-dictionary.js.map +1 -0
- package/dist/collections/default-map.d.ts.map +1 -0
- package/dist/collections/default-map.js.map +1 -0
- package/dist/collections/default-weak-map.d.ts.map +1 -0
- package/dist/collections/default-weak-map.js.map +1 -0
- package/dist/collections/from.d.ts.map +1 -0
- package/dist/collections/from.js.map +1 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/index.js.map +1 -0
- package/dist/debouncer.d.ts +60 -0
- package/dist/debouncer.d.ts.map +1 -0
- package/dist/debouncer.js +118 -0
- package/dist/debouncer.js.map +1 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js.map +1 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/{types/functions.d.ts → functions.d.ts} +5 -35
- package/dist/functions.d.ts.map +1 -0
- package/dist/{esm/functions.js → functions.js} +0 -85
- package/dist/functions.js.map +1 -0
- package/dist/{types/index.d.ts → index.d.ts} +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{web/index.js → index.js} +2 -0
- package/dist/index.js.map +1 -0
- package/dist/key-value-pair.d.ts.map +1 -0
- package/dist/key-value-pair.js.map +1 -0
- package/dist/keyed-debouncer.d.ts +56 -0
- package/dist/keyed-debouncer.d.ts.map +1 -0
- package/dist/keyed-debouncer.js +109 -0
- package/dist/keyed-debouncer.js.map +1 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js.map +1 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js.map +1 -0
- package/dist/order.d.ts.map +1 -0
- package/dist/order.js.map +1 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js.map +1 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js.map +1 -0
- package/dist/range.d.ts.map +1 -0
- package/dist/range.js.map +1 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js.map +1 -0
- package/dist/stopwatch.d.ts.map +1 -0
- package/dist/stopwatch.js.map +1 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js.map +1 -0
- package/dist/timer.d.ts.map +1 -0
- package/dist/timer.js.map +1 -0
- package/dist/timespan.d.ts.map +1 -0
- package/dist/timespan.js.map +1 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.js.map +1 -0
- package/dist/type-code.d.ts.map +1 -0
- package/dist/type-code.js.map +1 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js.map +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js.map +1 -0
- package/dist/{types/utilities.d.ts → utilities.d.ts} +8 -3
- package/dist/utilities.d.ts.map +1 -0
- package/dist/{web/utilities.js → utilities.js} +27 -4
- package/dist/utilities.js.map +1 -0
- package/package.json +13 -62
- package/src/debouncer.ts +135 -0
- package/src/functions.ts +5 -114
- package/src/index.ts +4 -0
- package/src/keyed-debouncer.ts +121 -0
- package/src/utilities.ts +30 -4
- package/dist/cjs/array.js +0 -106
- package/dist/cjs/array.js.map +0 -1
- package/dist/cjs/async-pool-executor.js +0 -79
- package/dist/cjs/async-pool-executor.js.map +0 -1
- package/dist/cjs/browser/form-utilities.js +0 -162
- package/dist/cjs/browser/form-utilities.js.map +0 -1
- package/dist/cjs/browser/geo-location.js +0 -78
- package/dist/cjs/browser/geo-location.js.map +0 -1
- package/dist/cjs/browser/index.js +0 -99
- package/dist/cjs/browser/index.js.map +0 -1
- package/dist/cjs/browser/native-bridge.js +0 -81
- package/dist/cjs/browser/native-bridge.js.map +0 -1
- package/dist/cjs/cancellable-promise.js +0 -81
- package/dist/cjs/cancellable-promise.js.map +0 -1
- package/dist/cjs/clean-url-search-params.js +0 -34
- package/dist/cjs/clean-url-search-params.js.map +0 -1
- package/dist/cjs/collections/cache-dictionary.js +0 -102
- package/dist/cjs/collections/cache-dictionary.js.map +0 -1
- package/dist/cjs/collections/default-map.js +0 -45
- package/dist/cjs/collections/default-map.js.map +0 -1
- package/dist/cjs/collections/default-weak-map.js +0 -46
- package/dist/cjs/collections/default-weak-map.js.map +0 -1
- package/dist/cjs/collections/from.js +0 -778
- package/dist/cjs/collections/from.js.map +0 -1
- package/dist/cjs/collections/index.js +0 -15
- package/dist/cjs/collections/index.js.map +0 -1
- package/dist/cjs/draft.js +0 -225
- package/dist/cjs/draft.js.map +0 -1
- package/dist/cjs/event-bus.js +0 -71
- package/dist/cjs/event-bus.js.map +0 -1
- package/dist/cjs/functions.js +0 -348
- package/dist/cjs/functions.js.map +0 -1
- package/dist/cjs/index.js +0 -80
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/key-value-pair.js +0 -22
- package/dist/cjs/key-value-pair.js.map +0 -1
- package/dist/cjs/lazy.js +0 -29
- package/dist/cjs/lazy.js.map +0 -1
- package/dist/cjs/math.js +0 -37
- package/dist/cjs/math.js.map +0 -1
- package/dist/cjs/order.js +0 -9
- package/dist/cjs/order.js.map +0 -1
- package/dist/cjs/parse.js +0 -174
- package/dist/cjs/parse.js.map +0 -1
- package/dist/cjs/patch.js +0 -52
- package/dist/cjs/patch.js.map +0 -1
- package/dist/cjs/range.js +0 -154
- package/dist/cjs/range.js.map +0 -1
- package/dist/cjs/result.js +0 -3
- package/dist/cjs/result.js.map +0 -1
- package/dist/cjs/stopwatch.js +0 -46
- package/dist/cjs/stopwatch.js.map +0 -1
- package/dist/cjs/string.js +0 -154
- package/dist/cjs/string.js.map +0 -1
- package/dist/cjs/timer.js +0 -57
- package/dist/cjs/timer.js.map +0 -1
- package/dist/cjs/timespan.js +0 -367
- package/dist/cjs/timespan.js.map +0 -1
- package/dist/cjs/triggers.js +0 -103
- package/dist/cjs/triggers.js.map +0 -1
- package/dist/cjs/type-code.js +0 -18
- package/dist/cjs/type-code.js.map +0 -1
- package/dist/cjs/type.js +0 -296
- package/dist/cjs/type.js.map +0 -1
- package/dist/cjs/types.js +0 -3
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/utilities.js +0 -598
- package/dist/cjs/utilities.js.map +0 -1
- package/dist/esm/array.js.map +0 -1
- package/dist/esm/async-pool-executor.js.map +0 -1
- package/dist/esm/browser/form-utilities.js.map +0 -1
- package/dist/esm/browser/geo-location.js.map +0 -1
- package/dist/esm/browser/index.js.map +0 -1
- package/dist/esm/browser/native-bridge.js.map +0 -1
- package/dist/esm/cancellable-promise.js.map +0 -1
- package/dist/esm/clean-url-search-params.js.map +0 -1
- package/dist/esm/collections/cache-dictionary.js.map +0 -1
- package/dist/esm/collections/default-map.js.map +0 -1
- package/dist/esm/collections/default-weak-map.js.map +0 -1
- package/dist/esm/collections/from.js.map +0 -1
- package/dist/esm/collections/index.js.map +0 -1
- package/dist/esm/draft.js.map +0 -1
- package/dist/esm/event-bus.js.map +0 -1
- package/dist/esm/functions.js.map +0 -1
- package/dist/esm/index.js +0 -38
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/key-value-pair.js.map +0 -1
- package/dist/esm/lazy.js.map +0 -1
- package/dist/esm/math.js.map +0 -1
- package/dist/esm/order.js.map +0 -1
- package/dist/esm/parse.js.map +0 -1
- package/dist/esm/patch.js.map +0 -1
- package/dist/esm/range.js.map +0 -1
- package/dist/esm/result.js.map +0 -1
- package/dist/esm/stopwatch.js.map +0 -1
- package/dist/esm/string.js.map +0 -1
- package/dist/esm/timer.js.map +0 -1
- package/dist/esm/timespan.js.map +0 -1
- package/dist/esm/triggers.js.map +0 -1
- package/dist/esm/type-code.js.map +0 -1
- package/dist/esm/type.js.map +0 -1
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utilities.js +0 -567
- package/dist/esm/utilities.js.map +0 -1
- package/dist/types/array.d.ts.map +0 -1
- package/dist/types/async-pool-executor.d.ts.map +0 -1
- package/dist/types/browser/form-utilities.d.ts.map +0 -1
- package/dist/types/browser/geo-location.d.ts.map +0 -1
- package/dist/types/browser/index.d.ts.map +0 -1
- package/dist/types/browser/native-bridge.d.ts.map +0 -1
- package/dist/types/cancellable-promise.d.ts.map +0 -1
- package/dist/types/clean-url-search-params.d.ts.map +0 -1
- package/dist/types/collections/cache-dictionary.d.ts.map +0 -1
- package/dist/types/collections/default-map.d.ts.map +0 -1
- package/dist/types/collections/default-weak-map.d.ts.map +0 -1
- package/dist/types/collections/from.d.ts.map +0 -1
- package/dist/types/collections/index.d.ts.map +0 -1
- package/dist/types/draft.d.ts.map +0 -1
- package/dist/types/event-bus.d.ts.map +0 -1
- package/dist/types/functions.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/key-value-pair.d.ts.map +0 -1
- package/dist/types/lazy.d.ts.map +0 -1
- package/dist/types/math.d.ts.map +0 -1
- package/dist/types/order.d.ts.map +0 -1
- package/dist/types/parse.d.ts.map +0 -1
- package/dist/types/patch.d.ts.map +0 -1
- package/dist/types/range.d.ts.map +0 -1
- package/dist/types/result.d.ts.map +0 -1
- package/dist/types/stopwatch.d.ts.map +0 -1
- package/dist/types/string.d.ts.map +0 -1
- package/dist/types/timer.d.ts.map +0 -1
- package/dist/types/timespan.d.ts.map +0 -1
- package/dist/types/triggers.d.ts.map +0 -1
- package/dist/types/type-code.d.ts.map +0 -1
- package/dist/types/type.d.ts.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/utilities.d.ts.map +0 -1
- package/dist/web/array.js +0 -98
- package/dist/web/array.js.map +0 -1
- package/dist/web/async-pool-executor.js +0 -76
- package/dist/web/async-pool-executor.js.map +0 -1
- package/dist/web/browser/form-utilities.js +0 -155
- package/dist/web/browser/form-utilities.js.map +0 -1
- package/dist/web/browser/geo-location.js +0 -75
- package/dist/web/browser/geo-location.js.map +0 -1
- package/dist/web/browser/index.js +0 -75
- package/dist/web/browser/index.js.map +0 -1
- package/dist/web/browser/native-bridge.js +0 -78
- package/dist/web/browser/native-bridge.js.map +0 -1
- package/dist/web/cancellable-promise.js +0 -78
- package/dist/web/cancellable-promise.js.map +0 -1
- package/dist/web/clean-url-search-params.js +0 -31
- package/dist/web/clean-url-search-params.js.map +0 -1
- package/dist/web/collections/cache-dictionary.js +0 -99
- package/dist/web/collections/cache-dictionary.js.map +0 -1
- package/dist/web/collections/default-map.js +0 -42
- package/dist/web/collections/default-map.js.map +0 -1
- package/dist/web/collections/default-weak-map.js +0 -43
- package/dist/web/collections/default-weak-map.js.map +0 -1
- package/dist/web/collections/from.js +0 -770
- package/dist/web/collections/from.js.map +0 -1
- package/dist/web/collections/index.js +0 -5
- package/dist/web/collections/index.js.map +0 -1
- package/dist/web/draft.js +0 -222
- package/dist/web/draft.js.map +0 -1
- package/dist/web/event-bus.js +0 -66
- package/dist/web/event-bus.js.map +0 -1
- package/dist/web/functions.js +0 -336
- package/dist/web/functions.js.map +0 -1
- package/dist/web/index.js.map +0 -1
- package/dist/web/key-value-pair.js +0 -19
- package/dist/web/key-value-pair.js.map +0 -1
- package/dist/web/lazy.js +0 -26
- package/dist/web/lazy.js.map +0 -1
- package/dist/web/math.js +0 -33
- package/dist/web/math.js.map +0 -1
- package/dist/web/order.js +0 -7
- package/dist/web/order.js.map +0 -1
- package/dist/web/parse.js +0 -169
- package/dist/web/parse.js.map +0 -1
- package/dist/web/patch.js +0 -48
- package/dist/web/patch.js.map +0 -1
- package/dist/web/range.js +0 -151
- package/dist/web/range.js.map +0 -1
- package/dist/web/result.js +0 -2
- package/dist/web/result.js.map +0 -1
- package/dist/web/stopwatch.js +0 -40
- package/dist/web/stopwatch.js.map +0 -1
- package/dist/web/string.js +0 -142
- package/dist/web/string.js.map +0 -1
- package/dist/web/timer.js +0 -54
- package/dist/web/timer.js.map +0 -1
- package/dist/web/timespan.js +0 -365
- package/dist/web/timespan.js.map +0 -1
- package/dist/web/triggers.js +0 -99
- package/dist/web/triggers.js.map +0 -1
- package/dist/web/type-code.js +0 -16
- package/dist/web/type-code.js.map +0 -1
- package/dist/web/type.js +0 -292
- package/dist/web/type.js.map +0 -1
- package/dist/web/types.js +0 -2
- package/dist/web/types.js.map +0 -1
- package/dist/web/utilities.js.map +0 -1
- /package/dist/{types/array.d.ts → array.d.ts} +0 -0
- /package/dist/{esm/array.js → array.js} +0 -0
- /package/dist/{types/async-pool-executor.d.ts → async-pool-executor.d.ts} +0 -0
- /package/dist/{esm/async-pool-executor.js → async-pool-executor.js} +0 -0
- /package/dist/{types/browser → browser}/form-utilities.d.ts +0 -0
- /package/dist/{esm/browser → browser}/form-utilities.js +0 -0
- /package/dist/{types/browser → browser}/geo-location.d.ts +0 -0
- /package/dist/{esm/browser → browser}/geo-location.js +0 -0
- /package/dist/{types/browser → browser}/index.d.ts +0 -0
- /package/dist/{esm/browser → browser}/index.js +0 -0
- /package/dist/{types/browser → browser}/native-bridge.d.ts +0 -0
- /package/dist/{esm/browser → browser}/native-bridge.js +0 -0
- /package/dist/{types/cancellable-promise.d.ts → cancellable-promise.d.ts} +0 -0
- /package/dist/{esm/cancellable-promise.js → cancellable-promise.js} +0 -0
- /package/dist/{types/clean-url-search-params.d.ts → clean-url-search-params.d.ts} +0 -0
- /package/dist/{esm/clean-url-search-params.js → clean-url-search-params.js} +0 -0
- /package/dist/{types/collections → collections}/cache-dictionary.d.ts +0 -0
- /package/dist/{esm/collections → collections}/cache-dictionary.js +0 -0
- /package/dist/{types/collections → collections}/default-map.d.ts +0 -0
- /package/dist/{esm/collections → collections}/default-map.js +0 -0
- /package/dist/{types/collections → collections}/default-weak-map.d.ts +0 -0
- /package/dist/{esm/collections → collections}/default-weak-map.js +0 -0
- /package/dist/{types/collections → collections}/from.d.ts +0 -0
- /package/dist/{esm/collections → collections}/from.js +0 -0
- /package/dist/{types/collections → collections}/index.d.ts +0 -0
- /package/dist/{esm/collections → collections}/index.js +0 -0
- /package/dist/{types/draft.d.ts → draft.d.ts} +0 -0
- /package/dist/{esm/draft.js → draft.js} +0 -0
- /package/dist/{types/event-bus.d.ts → event-bus.d.ts} +0 -0
- /package/dist/{esm/event-bus.js → event-bus.js} +0 -0
- /package/dist/{types/key-value-pair.d.ts → key-value-pair.d.ts} +0 -0
- /package/dist/{esm/key-value-pair.js → key-value-pair.js} +0 -0
- /package/dist/{types/lazy.d.ts → lazy.d.ts} +0 -0
- /package/dist/{esm/lazy.js → lazy.js} +0 -0
- /package/dist/{types/math.d.ts → math.d.ts} +0 -0
- /package/dist/{esm/math.js → math.js} +0 -0
- /package/dist/{types/order.d.ts → order.d.ts} +0 -0
- /package/dist/{esm/order.js → order.js} +0 -0
- /package/dist/{types/parse.d.ts → parse.d.ts} +0 -0
- /package/dist/{esm/parse.js → parse.js} +0 -0
- /package/dist/{types/patch.d.ts → patch.d.ts} +0 -0
- /package/dist/{esm/patch.js → patch.js} +0 -0
- /package/dist/{types/range.d.ts → range.d.ts} +0 -0
- /package/dist/{esm/range.js → range.js} +0 -0
- /package/dist/{types/result.d.ts → result.d.ts} +0 -0
- /package/dist/{esm/result.js → result.js} +0 -0
- /package/dist/{types/stopwatch.d.ts → stopwatch.d.ts} +0 -0
- /package/dist/{esm/stopwatch.js → stopwatch.js} +0 -0
- /package/dist/{types/string.d.ts → string.d.ts} +0 -0
- /package/dist/{esm/string.js → string.js} +0 -0
- /package/dist/{types/timer.d.ts → timer.d.ts} +0 -0
- /package/dist/{esm/timer.js → timer.js} +0 -0
- /package/dist/{types/timespan.d.ts → timespan.d.ts} +0 -0
- /package/dist/{esm/timespan.js → timespan.js} +0 -0
- /package/dist/{types/triggers.d.ts → triggers.d.ts} +0 -0
- /package/dist/{esm/triggers.js → triggers.js} +0 -0
- /package/dist/{types/type-code.d.ts → type-code.d.ts} +0 -0
- /package/dist/{esm/type-code.js → type-code.js} +0 -0
- /package/dist/{types/type.d.ts → type.d.ts} +0 -0
- /package/dist/{esm/type.js → type.js} +0 -0
- /package/dist/{types/types.d.ts → types.d.ts} +0 -0
- /package/dist/{esm/types.js → types.js} +0 -0
|
@@ -1,778 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Grouping = exports.From = void 0;
|
|
7
|
-
exports.default = from;
|
|
8
|
-
const utilities_js_1 = require("../utilities.js");
|
|
9
|
-
const order_js_1 = __importDefault(require("../order.js"));
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new From instance from an Iterable or a Supplier of an Iterable.
|
|
12
|
-
* @template T - The type of elements in the source.
|
|
13
|
-
* @param {Iterable<T> | Supplier<Iterable<T>>} source - The source data.
|
|
14
|
-
* @returns {From<T> | From<KeyValuePair<any, any>>} A new From instance.
|
|
15
|
-
* @throws {Error} If source is null or invalid.
|
|
16
|
-
*/
|
|
17
|
-
function from(source) {
|
|
18
|
-
if (source == null)
|
|
19
|
-
throw new Error("Source is null.");
|
|
20
|
-
if (typeof source === 'function')
|
|
21
|
-
return From.fn(source);
|
|
22
|
-
if (typeof source[Symbol.iterator] === 'function') {
|
|
23
|
-
return From.iterable(source);
|
|
24
|
-
}
|
|
25
|
-
else if (typeof source === 'object') {
|
|
26
|
-
return From.object(source);
|
|
27
|
-
}
|
|
28
|
-
throw new Error("Invalid source.");
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* A LINQ-like wrapper for iterables that provides various transformation and query methods.
|
|
32
|
-
* @template T - The type of elements in the sequence.
|
|
33
|
-
*/
|
|
34
|
-
class From {
|
|
35
|
-
/**
|
|
36
|
-
* Creates a From instance from an object's entries.
|
|
37
|
-
* @param {any} obj - The object to convert to pairs.
|
|
38
|
-
* @returns {From<KeyValuePair<any, any>>} A From instance of key-value pairs.
|
|
39
|
-
*/
|
|
40
|
-
static object(obj) {
|
|
41
|
-
return new From(function () {
|
|
42
|
-
return (0, utilities_js_1.toPairs)(obj);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
constructor(fn) {
|
|
46
|
-
this._fn = fn;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Creates a From instance from a supplier function.
|
|
50
|
-
* @template T
|
|
51
|
-
* @param {Supplier<Iterable<T>>} callable - A function that returns an Iterable.
|
|
52
|
-
* @returns {From<T>} A new From instance.
|
|
53
|
-
*/
|
|
54
|
-
static fn(callable) {
|
|
55
|
-
return new From(callable);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Collects all elements into an array and returns a new From instance from it.
|
|
59
|
-
* Useful for freezing the sequence and preventing multiple iterations over a generator.
|
|
60
|
-
* @returns {From<T>} A new From instance with cached data.
|
|
61
|
-
*/
|
|
62
|
-
collect() {
|
|
63
|
-
const cache = Array.from(this);
|
|
64
|
-
return From.iterable(cache);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Creates a From instance from an Iterable.
|
|
68
|
-
* @template T
|
|
69
|
-
* @param {Iterable<T>} iterable - The source iterable.
|
|
70
|
-
* @returns {From<T>} A new From instance.
|
|
71
|
-
*/
|
|
72
|
-
static iterable(iterable) {
|
|
73
|
-
return From.fn(function* () {
|
|
74
|
-
for (const item of iterable) {
|
|
75
|
-
yield item;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Maps each element of the sequence into a new form.
|
|
81
|
-
* @template R
|
|
82
|
-
* @param {UnaryFunction<T, R>} mapper - A transformation function.
|
|
83
|
-
* @returns {From<R>} A new From instance with the mapped elements.
|
|
84
|
-
*/
|
|
85
|
-
map(mapper) {
|
|
86
|
-
const self = this;
|
|
87
|
-
return From.fn(function* () {
|
|
88
|
-
for (let item of self) {
|
|
89
|
-
yield mapper(item);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
*[Symbol.iterator]() {
|
|
94
|
-
yield* this._fn();
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Checks if all elements in the sequence satisfy the given predicate.
|
|
98
|
-
* @param {Predicate<T>} predicate - A function to test each element.
|
|
99
|
-
* @returns {boolean} True if all elements satisfy the predicate.
|
|
100
|
-
*/
|
|
101
|
-
all(predicate) {
|
|
102
|
-
for (let item of this._fn()) {
|
|
103
|
-
if (!predicate(item)) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Checks if any element in the sequence satisfies the given predicate.
|
|
111
|
-
* If no predicate is provided, checks if the sequence is not empty.
|
|
112
|
-
* @param {Predicate<T>} [predicate] - A function to test each element.
|
|
113
|
-
* @returns {boolean} True if any element satisfies the predicate.
|
|
114
|
-
*/
|
|
115
|
-
any(predicate) {
|
|
116
|
-
for (let item of this) {
|
|
117
|
-
if (predicate == null || predicate(item)) {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Gets the number of elements in the sequence.
|
|
125
|
-
* @returns {number} The count of elements.
|
|
126
|
-
*/
|
|
127
|
-
get length() {
|
|
128
|
-
return this.count();
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Counts the number of elements that satisfy the given predicate.
|
|
132
|
-
* If no predicate is provided, counts all elements.
|
|
133
|
-
* @param {Predicate<T>} [predicate] - A function to test each element.
|
|
134
|
-
* @returns {number} The count of elements.
|
|
135
|
-
*/
|
|
136
|
-
count(predicate) {
|
|
137
|
-
let output = 0;
|
|
138
|
-
for (let item of this) {
|
|
139
|
-
if (predicate == null || predicate(item)) {
|
|
140
|
-
output++;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return output;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Filters the sequence based on a predicate.
|
|
147
|
-
* @param {Predicate<T>} predicate - A function to test each element.
|
|
148
|
-
* @returns {From<T>} A new From instance with the filtered elements.
|
|
149
|
-
*/
|
|
150
|
-
filter(predicate) {
|
|
151
|
-
const self = this;
|
|
152
|
-
return From.fn(function* () {
|
|
153
|
-
for (let item of self) {
|
|
154
|
-
if (predicate(item)) {
|
|
155
|
-
yield item;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Checks if the sequence contains a specific value.
|
|
162
|
-
* @param {T} value - The value to search for.
|
|
163
|
-
* @returns {boolean} True if the value is found.
|
|
164
|
-
*/
|
|
165
|
-
contains(value) {
|
|
166
|
-
for (let item of this) {
|
|
167
|
-
if (item === value) {
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Returns the first element of the sequence that satisfies a condition.
|
|
175
|
-
* @param {Predicate<T>} [predicate] - Optional condition.
|
|
176
|
-
* @returns {T | undefined} The first element or undefined.
|
|
177
|
-
*/
|
|
178
|
-
first(predicate) {
|
|
179
|
-
if (predicate) {
|
|
180
|
-
for (let item of this) {
|
|
181
|
-
if (predicate(item)) {
|
|
182
|
-
return item;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
// noinspection LoopStatementThatDoesntLoopJS
|
|
188
|
-
for (let item of this) {
|
|
189
|
-
return item;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return undefined;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Returns the only element of the sequence that satisfies a condition, or throws if more than one exists.
|
|
196
|
-
* @param {Predicate<T>} [predicate] - Optional condition.
|
|
197
|
-
* @returns {T | null} The single element or null if not found.
|
|
198
|
-
* @throws {Error} If more than one element is found.
|
|
199
|
-
*/
|
|
200
|
-
single(predicate) {
|
|
201
|
-
let found = false;
|
|
202
|
-
let output = null;
|
|
203
|
-
if (predicate) {
|
|
204
|
-
for (let item of this) {
|
|
205
|
-
if (predicate(item)) {
|
|
206
|
-
if (found) {
|
|
207
|
-
throw new Error("Sequence contains more than one element.");
|
|
208
|
-
}
|
|
209
|
-
found = true;
|
|
210
|
-
output = item;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
// noinspection LoopStatementThatDoesntLoopJS
|
|
216
|
-
for (let item of this) {
|
|
217
|
-
if (found) {
|
|
218
|
-
throw new Error("Sequence contains more than one element.");
|
|
219
|
-
}
|
|
220
|
-
found = true;
|
|
221
|
-
output = item;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return output;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Appends an item to the end of the sequence.
|
|
228
|
-
* @param {T} item - The item to append.
|
|
229
|
-
* @returns {From<T>} A new From instance.
|
|
230
|
-
*/
|
|
231
|
-
append(item) {
|
|
232
|
-
const self = this;
|
|
233
|
-
return From.fn(function* () {
|
|
234
|
-
for (let element of self) {
|
|
235
|
-
yield element;
|
|
236
|
-
}
|
|
237
|
-
yield item;
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Prepends an item to the beginning of the sequence.
|
|
242
|
-
* @param {T} item - The item to prepend.
|
|
243
|
-
* @returns {From<T>} A new From instance.
|
|
244
|
-
*/
|
|
245
|
-
prepend(item) {
|
|
246
|
-
const self = this;
|
|
247
|
-
return From.fn(function* () {
|
|
248
|
-
yield item;
|
|
249
|
-
for (let element of self) {
|
|
250
|
-
yield element;
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Gets the element at a specific index.
|
|
256
|
-
* @param {number} index - The zero-based index.
|
|
257
|
-
* @returns {T | undefined} The element at the index or undefined.
|
|
258
|
-
*/
|
|
259
|
-
at(index) {
|
|
260
|
-
let idx = 0;
|
|
261
|
-
for (let item of this) {
|
|
262
|
-
if (idx++ === index) {
|
|
263
|
-
return item;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return undefined;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Returns the last element of the sequence that satisfies a condition.
|
|
270
|
-
* @param {Predicate<T>} [predicate] - Optional condition.
|
|
271
|
-
* @returns {T | undefined} The last element or undefined.
|
|
272
|
-
*/
|
|
273
|
-
last(predicate) {
|
|
274
|
-
let last = undefined;
|
|
275
|
-
if (predicate)
|
|
276
|
-
for (let item of this) {
|
|
277
|
-
if (!predicate || predicate(item)) {
|
|
278
|
-
last = item;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
for (let item of this) {
|
|
283
|
-
last = item;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return last;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Projects each element of a sequence to an Iterable and flattens the resulting sequences into one sequence.
|
|
290
|
-
* @template R
|
|
291
|
-
* @param {UnaryFunction<T, Iterable<R>>} mapper - A transformation function.
|
|
292
|
-
* @returns {From<R>} A new From instance.
|
|
293
|
-
*/
|
|
294
|
-
mapMany(mapper) {
|
|
295
|
-
const self = this;
|
|
296
|
-
return From.fn(function* () {
|
|
297
|
-
for (const item of self) {
|
|
298
|
-
const subitems = mapper(item);
|
|
299
|
-
for (const subitem of subitems) {
|
|
300
|
-
yield subitem;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Flattens a sequence of iterables.
|
|
307
|
-
* @returns {From<any>} A new From instance.
|
|
308
|
-
*/
|
|
309
|
-
flatten() {
|
|
310
|
-
const self = this;
|
|
311
|
-
return From.fn(function* () {
|
|
312
|
-
for (let item of self) {
|
|
313
|
-
let temp = item;
|
|
314
|
-
for (let subitem of temp) {
|
|
315
|
-
yield subitem;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Calculates the sum of the elements in the sequence.
|
|
322
|
-
* @param {UnaryFunction<T, number>} [mapper] - Optional projection function.
|
|
323
|
-
* @returns {number} The sum.
|
|
324
|
-
*/
|
|
325
|
-
sum(mapper) {
|
|
326
|
-
let total = 0;
|
|
327
|
-
if (mapper)
|
|
328
|
-
for (let item of this) {
|
|
329
|
-
total += mapper(item);
|
|
330
|
-
}
|
|
331
|
-
else
|
|
332
|
-
for (let item of this) {
|
|
333
|
-
total += item;
|
|
334
|
-
}
|
|
335
|
-
return total;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Calculates the average of the elements in the sequence.
|
|
339
|
-
* @param {UnaryFunction<T, number>} [mapper] - Optional projection function.
|
|
340
|
-
* @returns {number} The average.
|
|
341
|
-
*/
|
|
342
|
-
avg(mapper) {
|
|
343
|
-
let total = 0;
|
|
344
|
-
let count = 0;
|
|
345
|
-
if (mapper)
|
|
346
|
-
for (let item of this) {
|
|
347
|
-
total += mapper(item);
|
|
348
|
-
count++;
|
|
349
|
-
}
|
|
350
|
-
else
|
|
351
|
-
for (let item of this) {
|
|
352
|
-
total += item;
|
|
353
|
-
count++;
|
|
354
|
-
}
|
|
355
|
-
return count > 0 ? total / count : 0;
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Returns the maximum value in the sequence.
|
|
359
|
-
* @param {UnaryFunction<T, number>} mapper - Projection function.
|
|
360
|
-
* @returns {number} The maximum value.
|
|
361
|
-
*/
|
|
362
|
-
max(mapper) {
|
|
363
|
-
let max = -Infinity;
|
|
364
|
-
for (let item of this) {
|
|
365
|
-
let value = mapper(item);
|
|
366
|
-
max = value > max ? value : max;
|
|
367
|
-
}
|
|
368
|
-
return max;
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Returns the minimum value in the sequence.
|
|
372
|
-
* @param {UnaryFunction<T, number>} mapper - Projection function.
|
|
373
|
-
* @returns {number} The minimum value.
|
|
374
|
-
*/
|
|
375
|
-
min(mapper) {
|
|
376
|
-
let min = Infinity;
|
|
377
|
-
for (let item of this) {
|
|
378
|
-
let value = mapper(item);
|
|
379
|
-
min = value < min ? value : min;
|
|
380
|
-
}
|
|
381
|
-
return min;
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Returns the element with the maximum value.
|
|
385
|
-
* @param {UnaryFunction<T, number>} mapper - Projection function.
|
|
386
|
-
* @returns {T | undefined} The element with the maximum value.
|
|
387
|
-
*/
|
|
388
|
-
maxBy(mapper) {
|
|
389
|
-
let max = -Infinity;
|
|
390
|
-
let maxItem;
|
|
391
|
-
for (let item of this) {
|
|
392
|
-
let value = mapper(item);
|
|
393
|
-
if (value > max) {
|
|
394
|
-
max = value;
|
|
395
|
-
maxItem = item;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
return maxItem;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Returns the element with the minimum value.
|
|
402
|
-
* @param {UnaryFunction<T, number>} mapper - Projection function.
|
|
403
|
-
* @returns {T | undefined} The element with the minimum value.
|
|
404
|
-
*/
|
|
405
|
-
minBy(mapper) {
|
|
406
|
-
let min = Infinity;
|
|
407
|
-
let minItem;
|
|
408
|
-
for (let item of this) {
|
|
409
|
-
let value = mapper(item);
|
|
410
|
-
if (value < min) {
|
|
411
|
-
min = value;
|
|
412
|
-
minItem = item;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
return minItem;
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Sorts the elements of the sequence.
|
|
419
|
-
* @template R
|
|
420
|
-
* @param {UnaryFunction<T, R>} mapper - Projection function for the key to sort by.
|
|
421
|
-
* @param {Order} [order] - Ascending or Descending.
|
|
422
|
-
* @returns {From<T>} A new From instance.
|
|
423
|
-
*/
|
|
424
|
-
orderBy(mapper, order = order_js_1.default.Ascending) {
|
|
425
|
-
const array = Array.from(this._fn());
|
|
426
|
-
if (order == order_js_1.default.Ascending) {
|
|
427
|
-
array.sort((a, b) => {
|
|
428
|
-
const aValue = mapper(a);
|
|
429
|
-
const bValue = mapper(b);
|
|
430
|
-
return aValue > bValue ? 1 : bValue > aValue ? -1 : 0;
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
else if (order == order_js_1.default.Descending) {
|
|
434
|
-
array.sort((a, b) => {
|
|
435
|
-
const aValue = mapper(a);
|
|
436
|
-
const bValue = mapper(b);
|
|
437
|
-
return aValue > bValue ? 1 : bValue < aValue ? -1 : 0;
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
else {
|
|
441
|
-
throw new Error("invalid order argument");
|
|
442
|
-
}
|
|
443
|
-
return From.iterable(array);
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Groups the elements of the sequence.
|
|
447
|
-
* @template TKey
|
|
448
|
-
* @param {UnaryFunction<T, TKey>} keySelector - Function to extract the key for each element.
|
|
449
|
-
* @param {EqualityComparer<TKey>} [equalityComparer] - Optional comparer for keys.
|
|
450
|
-
* @returns {From<Grouping<TKey, T>>} A new From instance.
|
|
451
|
-
*/
|
|
452
|
-
groupBy(keySelector, equalityComparer) {
|
|
453
|
-
equalityComparer = (equalityComparer == null ? utilities_js_1.shallowEqual : equalityComparer);
|
|
454
|
-
const self = this;
|
|
455
|
-
return From.fn(function* () {
|
|
456
|
-
const groups = [];
|
|
457
|
-
for (let item of self) {
|
|
458
|
-
const key = keySelector(item);
|
|
459
|
-
let found = false;
|
|
460
|
-
for (let [entryKey, group] of groups) {
|
|
461
|
-
if (equalityComparer(key, entryKey)) {
|
|
462
|
-
group.push(item);
|
|
463
|
-
found = true;
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
if (!found) {
|
|
468
|
-
groups.push([key, [item]]);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
yield* groups.map(([key, values]) => new Grouping(key, values));
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
/**
|
|
475
|
-
* Returns a specified number of contiguous elements from the start of the sequence.
|
|
476
|
-
* @param {number} n - The number of elements to return.
|
|
477
|
-
* @returns {From<T>} A new From instance.
|
|
478
|
-
*/
|
|
479
|
-
head(n) {
|
|
480
|
-
const self = this;
|
|
481
|
-
return From.fn(function* () {
|
|
482
|
-
let count = 0;
|
|
483
|
-
for (let item of self) {
|
|
484
|
-
if (count++ < n) {
|
|
485
|
-
yield item;
|
|
486
|
-
}
|
|
487
|
-
else {
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* Returns a specified number of contiguous elements from the end of the sequence.
|
|
495
|
-
* @param {number} n - The number of elements to return.
|
|
496
|
-
* @returns {From<T>} A new From instance.
|
|
497
|
-
*/
|
|
498
|
-
tail(n) {
|
|
499
|
-
const self = this;
|
|
500
|
-
return From.fn(function* () {
|
|
501
|
-
let buffer = [];
|
|
502
|
-
for (let item of self) {
|
|
503
|
-
buffer.push(item);
|
|
504
|
-
if (buffer.length > n) {
|
|
505
|
-
buffer.shift();
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
yield* buffer;
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* Performs the specified action on each element of the sequence.
|
|
513
|
-
* @param {Consumer<T>} action - The action to perform.
|
|
514
|
-
*/
|
|
515
|
-
forEach(action) {
|
|
516
|
-
for (let item of this) {
|
|
517
|
-
action(item);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
/**
|
|
521
|
-
* Converts the sequence to an array.
|
|
522
|
-
* @returns {T[]} The array.
|
|
523
|
-
*/
|
|
524
|
-
toArray() {
|
|
525
|
-
return Array.from(this);
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Converts the sequence to a record.
|
|
529
|
-
* @template R
|
|
530
|
-
* @param {UnaryFunction<T, string | symbol | number>} keySelector - Key selector.
|
|
531
|
-
* @param {UnaryFunction<T, R>} valueSelector - Value selector.
|
|
532
|
-
* @returns {Record<string | symbol | number, R>} The record.
|
|
533
|
-
*/
|
|
534
|
-
toRecord(keySelector, valueSelector) {
|
|
535
|
-
const output = {};
|
|
536
|
-
for (let item of this) {
|
|
537
|
-
output[keySelector(item)] = valueSelector(item);
|
|
538
|
-
}
|
|
539
|
-
return output;
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* Converts the sequence to a Map.
|
|
543
|
-
* @template RKey, RValue
|
|
544
|
-
* @param {UnaryFunction<T, RKey>} keySelector - Key selector.
|
|
545
|
-
* @param {UnaryFunction<T, RValue>} valueSelector - Value selector.
|
|
546
|
-
* @returns {Map<RKey, RValue>} The map.
|
|
547
|
-
*/
|
|
548
|
-
toMap(keySelector, valueSelector) {
|
|
549
|
-
const map = new Map();
|
|
550
|
-
for (let item of this) {
|
|
551
|
-
const key = keySelector(item);
|
|
552
|
-
const value = valueSelector(item);
|
|
553
|
-
map.set(key, value);
|
|
554
|
-
}
|
|
555
|
-
return map;
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* Returns elements that are instances of a specific primitive type.
|
|
559
|
-
* @param {string} type - The type string (e.g., 'string', 'number').
|
|
560
|
-
* @returns {From<T>} A new From instance.
|
|
561
|
-
*/
|
|
562
|
-
instancesOf(type) {
|
|
563
|
-
return this.filter(item => typeof item === type);
|
|
564
|
-
}
|
|
565
|
-
/**
|
|
566
|
-
* Checks if all elements are instances of a specific class.
|
|
567
|
-
* @param {new (...args: any[]) => any} type - The class constructor.
|
|
568
|
-
* @returns {boolean} True if all elements are instances of the type.
|
|
569
|
-
*/
|
|
570
|
-
allInstanceOf(type) {
|
|
571
|
-
for (let item of this) {
|
|
572
|
-
if (!(item instanceof type)) {
|
|
573
|
-
return false;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
return true;
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Returns distinct elements from the sequence.
|
|
580
|
-
* @param {EqualityComparer<T>} [eq_comparer] - Optional equality comparer.
|
|
581
|
-
* @returns {From<T>} A new From instance.
|
|
582
|
-
*/
|
|
583
|
-
distinct(eq_comparer) {
|
|
584
|
-
if (eq_comparer == null)
|
|
585
|
-
eq_comparer = utilities_js_1.shallowEqual;
|
|
586
|
-
const self = this;
|
|
587
|
-
return From.fn(function* () {
|
|
588
|
-
const included = [];
|
|
589
|
-
for (let item of self) {
|
|
590
|
-
if (!From.iterable(included).any(x => eq_comparer(x, item))) {
|
|
591
|
-
included.push(item);
|
|
592
|
-
yield item;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* Inserts an item at a specific index.
|
|
599
|
-
* @param {T} item - The item to insert.
|
|
600
|
-
* @param {number} index - The zero-based index.
|
|
601
|
-
* @returns {From<T>} A new From instance.
|
|
602
|
-
*/
|
|
603
|
-
insert(item, index) {
|
|
604
|
-
const self = this;
|
|
605
|
-
return From.fn(function* () {
|
|
606
|
-
let i = 0;
|
|
607
|
-
let inserted = false;
|
|
608
|
-
for (let existingItem of self) {
|
|
609
|
-
if (i === index) {
|
|
610
|
-
yield item;
|
|
611
|
-
inserted = true;
|
|
612
|
-
}
|
|
613
|
-
yield existingItem;
|
|
614
|
-
i++;
|
|
615
|
-
}
|
|
616
|
-
if (!inserted) {
|
|
617
|
-
yield item;
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Bypasses a specified number of elements in a sequence and then returns the remaining elements.
|
|
623
|
-
* @param {number} n - The number of elements to skip.
|
|
624
|
-
* @returns {From<T>} A new From instance.
|
|
625
|
-
*/
|
|
626
|
-
skip(n) {
|
|
627
|
-
const self = this;
|
|
628
|
-
return From.fn(function* () {
|
|
629
|
-
let i = 0;
|
|
630
|
-
for (let item of self) {
|
|
631
|
-
if (i >= n) {
|
|
632
|
-
yield item;
|
|
633
|
-
}
|
|
634
|
-
i++;
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Concatenates two sequences.
|
|
640
|
-
* @param {Iterable<T>} other - The other sequence.
|
|
641
|
-
* @returns {From<T>} A new From instance.
|
|
642
|
-
*/
|
|
643
|
-
union(other) {
|
|
644
|
-
const self = this;
|
|
645
|
-
return From.fn(function* () {
|
|
646
|
-
yield* self;
|
|
647
|
-
yield* other;
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* Correlates the elements of two sequences based on matching keys.
|
|
652
|
-
* @template T2, R, R2
|
|
653
|
-
* @param {Iterable<T2>} other - The other sequence.
|
|
654
|
-
* @param {UnaryFunction<T, R>} thisKeySelector - Key selector for this sequence.
|
|
655
|
-
* @param {UnaryFunction<T2, R>} otherKeySelector - Key selector for the other sequence.
|
|
656
|
-
* @param {(thisItem: T, otherItem: T2) => R2} resultSelector - Function to create a result element from two matching elements.
|
|
657
|
-
* @returns {From<R2>} A new From instance.
|
|
658
|
-
*/
|
|
659
|
-
innerJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
|
|
660
|
-
const self = this;
|
|
661
|
-
return From.fn(() => {
|
|
662
|
-
const otherByKey = new Map();
|
|
663
|
-
for (let item of other) {
|
|
664
|
-
otherByKey.set(otherKeySelector(item), item);
|
|
665
|
-
}
|
|
666
|
-
return Array.from(self)
|
|
667
|
-
.filter(item => otherByKey.has(thisKeySelector(item)))
|
|
668
|
-
.map(item => resultSelector(item, otherByKey.get(thisKeySelector(item))));
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
/**
|
|
672
|
-
* Performs a left join on two sequences.
|
|
673
|
-
* @template U, K, R
|
|
674
|
-
* @param {Iterable<U>} other - The other sequence.
|
|
675
|
-
* @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
|
|
676
|
-
* @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
|
|
677
|
-
* @param {(thisItem: T, otherItem: U | undefined) => R} resultSelector - Function to create a result element.
|
|
678
|
-
* @returns {From<R>} A new From instance.
|
|
679
|
-
*/
|
|
680
|
-
leftJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
|
|
681
|
-
const self = this;
|
|
682
|
-
return From.fn(() => {
|
|
683
|
-
const otherByKey = new Map();
|
|
684
|
-
for (let item of other) {
|
|
685
|
-
otherByKey.set(otherKeySelector(item), item);
|
|
686
|
-
}
|
|
687
|
-
return Array.from(self).map(item => resultSelector(item, otherByKey.get(thisKeySelector(item))));
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* Performs a left group join on two sequences.
|
|
692
|
-
* @template U, K, R
|
|
693
|
-
* @param {Iterable<U>} other - The other sequence.
|
|
694
|
-
* @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
|
|
695
|
-
* @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
|
|
696
|
-
* @param {(thisItem: T, otherItems: Array<U>) => R} resultSelector - Function to create a result element.
|
|
697
|
-
* @returns {From<R>} A new From instance.
|
|
698
|
-
*/
|
|
699
|
-
leftGroupJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
|
|
700
|
-
const self = this;
|
|
701
|
-
return From.fn(() => {
|
|
702
|
-
const otherByKeys = new Map();
|
|
703
|
-
for (let item of other) {
|
|
704
|
-
const key = otherKeySelector(item);
|
|
705
|
-
if (!otherByKeys.has(key)) {
|
|
706
|
-
otherByKeys.set(key, []);
|
|
707
|
-
}
|
|
708
|
-
otherByKeys.get(key).push(item);
|
|
709
|
-
}
|
|
710
|
-
return Array.from(self).map(item => resultSelector(item, otherByKeys.get(thisKeySelector(item)) || []));
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
|
-
* Performs a right group join on two sequences.
|
|
715
|
-
* @template U, K, R
|
|
716
|
-
* @param {Iterable<U>} other - The other sequence.
|
|
717
|
-
* @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
|
|
718
|
-
* @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
|
|
719
|
-
* @param {(thisItems: Array<T>, otherItem: U) => R} resultSelector - Function to create a result element.
|
|
720
|
-
* @returns {From<R>} A new From instance.
|
|
721
|
-
*/
|
|
722
|
-
rightGroupJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
|
|
723
|
-
const self = this;
|
|
724
|
-
return From.fn(() => {
|
|
725
|
-
const thisByKeys = new Map();
|
|
726
|
-
for (let item of self) {
|
|
727
|
-
const key = thisKeySelector(item);
|
|
728
|
-
if (!thisByKeys.has(key)) {
|
|
729
|
-
thisByKeys.set(key, []);
|
|
730
|
-
}
|
|
731
|
-
thisByKeys.get(key).push(item);
|
|
732
|
-
}
|
|
733
|
-
return Array.from(other).map(item => resultSelector(thisByKeys.get(otherKeySelector(item)) || [], item));
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
/**
|
|
737
|
-
* Performs a right join on two sequences.
|
|
738
|
-
* @template U, K, R
|
|
739
|
-
* @param {Iterable<U>} other - The other sequence.
|
|
740
|
-
* @param {UnaryFunction<T, K>} thisKeySelector - Key selector for this sequence.
|
|
741
|
-
* @param {UnaryFunction<U, K>} otherKeySelector - Key selector for the other sequence.
|
|
742
|
-
* @param {(thisItem: T | undefined, otherItem: U) => R} resultSelector - Function to create a result element.
|
|
743
|
-
* @returns {From<R>} A new From instance.
|
|
744
|
-
*/
|
|
745
|
-
rightJoin(other, thisKeySelector, otherKeySelector, resultSelector) {
|
|
746
|
-
const self = this;
|
|
747
|
-
return From.fn(() => {
|
|
748
|
-
const thisByKey = new Map();
|
|
749
|
-
for (let item of self) {
|
|
750
|
-
thisByKey.set(thisKeySelector(item), item);
|
|
751
|
-
}
|
|
752
|
-
return Array.from(other).map(item => resultSelector(thisByKey.get(otherKeySelector(item)), item));
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
exports.From = From;
|
|
757
|
-
/**
|
|
758
|
-
* Represents a group of elements that have a common key.
|
|
759
|
-
* @template TKey, T
|
|
760
|
-
*/
|
|
761
|
-
class Grouping extends From {
|
|
762
|
-
/**
|
|
763
|
-
* Gets the key of the group.
|
|
764
|
-
*/
|
|
765
|
-
get key() {
|
|
766
|
-
return this._key;
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* @param {TKey} key - The group key.
|
|
770
|
-
* @param {Array<T>} values - The values in the group.
|
|
771
|
-
*/
|
|
772
|
-
constructor(key, values) {
|
|
773
|
-
super(() => values);
|
|
774
|
-
this._key = key;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
exports.Grouping = Grouping;
|
|
778
|
-
//# sourceMappingURL=from.js.map
|