iterable-linq-utility 0.11.0 → 0.12.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/dist/index.d.cts CHANGED
@@ -317,6 +317,26 @@ declare function entries<T>(iterable: Iterable<T>): Iterable<[number, T]>;
317
317
  */
318
318
  declare function every<T>(iterable: Iterable<T>, predicate: Predicate<T>): boolean;
319
319
 
320
+ /**
321
+ * Lazily yields the distinct values of `iterable` that are not in `other`, in the order of `iterable`.
322
+ * Before the first value it reads the whole `other` into a `Set`, so `other` must be finite; each run reads it again.
323
+ * Values, or the keys returned by `keySelector`, are compared with `SameValueZero`, like `Set`: for each key the first value of `iterable` is yielded.
324
+ * If `keySelector` throws, or `other` throws, the sources are closed and the error propagates.
325
+ * @operation `Transformation`
326
+ * @param iterable - the source `Iterable`
327
+ * @param other - the `Iterable` whose values, or keys, are left out
328
+ * @param keySelector - called with every value of `iterable` and of `other`, and its index in its own source; omitted or `undefined` compares the values
329
+ * @returns a lazy, re-runnable `Iterable` of the distinct values of `iterable` that are not in `other`
330
+ * @throws Error if `iterable` or `other` is missing or does not implement `[Symbol.iterator]`, or if a provided `keySelector` is not a function
331
+ * @example
332
+ * ```ts
333
+ * Array.from(Functions.except([1, 2, 2, 3], [3, 4])); // [1, 2]
334
+ * Array.from(Functions.except([{ id: 1 }, { id: 2 }], [{ id: 2 }], v => v.id)); // [{ id: 1 }]
335
+ * ```
336
+ * @since 0.12.0
337
+ */
338
+ declare function except<T, K>(iterable: Iterable<T>, other: Iterable<T>, keySelector?: Mapper<T, K>): Iterable<T>;
339
+
320
340
  /**
321
341
  * Adds a method to every chain, including the chains created before the call.
322
342
  * Declare the method first by augmenting `IIterableLinq`, then register it at application start-up.
@@ -664,6 +684,7 @@ declare namespace Functions {
664
684
  empty_2 as empty,
665
685
  entries,
666
686
  every,
687
+ except,
667
688
  filter,
668
689
  find,
669
690
  findIndex,
@@ -674,8 +695,12 @@ declare namespace Functions {
674
695
  forEach,
675
696
  forEachAsync,
676
697
  fromObject_2 as fromObject,
698
+ groupBy,
699
+ groupJoin,
677
700
  includes,
678
701
  indexOf,
702
+ innerJoin,
703
+ intersect,
679
704
  join,
680
705
  lastIndexOf,
681
706
  map,
@@ -703,6 +728,7 @@ declare namespace Functions {
703
728
  takeWhile,
704
729
  tap,
705
730
  tapChain,
731
+ union,
706
732
  withValue as with,
707
733
  zip
708
734
  }
@@ -716,6 +742,52 @@ export { Functions }
716
742
  */
717
743
  declare function getMemoizeDefaultOptions(): IMemoizeOptions;
718
744
 
745
+ /**
746
+ * Lazily yields one `[key, values]` pair for each key returned by `keySelector`, in the order of the first appearance of the key;
747
+ * the values of a group are in the order of the source.
748
+ * The whole source is read before the first group is yielded, so `groupBy` does not end on an infinite source.
749
+ * Every iteration reads the source again and builds new arrays.
750
+ * The keys are compared with `SameValueZero`, like `Map`: `NaN` is one key, `null` and `undefined` are keys too.
751
+ * If `keySelector` throws, the source is closed and the error propagates.
752
+ * @operation `Transformation`
753
+ * @param iterable - the source `Iterable`
754
+ * @param keySelector - called with each value and its index; returns the key of the group of the value
755
+ * @returns a lazy, re-runnable `Iterable` of `[key, values]` pairs
756
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `keySelector` is not a function
757
+ * @example
758
+ * ```ts
759
+ * Array.from(Functions.groupBy([1, 2, 3, 4, 5], v => v % 2)); // [[1, [1, 3, 5]], [0, [2, 4]]]
760
+ * ```
761
+ * @since 0.12.0
762
+ */
763
+ declare function groupBy<T, K>(iterable: Iterable<T>, keySelector: Mapper<T, K>): Iterable<[K, T[]]>;
764
+
765
+ /**
766
+ * Lazily yields `result(outer, inners)` for each value of `iterable`, with the values of `inner` that have the same key,
767
+ * in the order of `inner`; `inners` is empty when there are none.
768
+ * Before the first value it reads the whole `inner`, so `inner` must be finite; each run reads it again.
769
+ * The keys are compared with `SameValueZero`, like `Map`: `NaN` matches `NaN`, and `null` and `undefined` match themselves.
770
+ * Each call of `result` gets a new array.
771
+ * If a callback throws, or `inner` throws, the source is closed and the error propagates.
772
+ * @operation `Transformation`
773
+ * @param iterable - the source `Iterable`, the outer values
774
+ * @param inner - the `Iterable` whose values are joined to the outer values
775
+ * @param outerKey - called with each value of `iterable` and its index; returns its key
776
+ * @param innerKey - called with each value of `inner` and its index; returns its key
777
+ * @param result - called with each outer value and the array of its inner values; returns the value to yield
778
+ * @returns a lazy, re-runnable `Iterable` with one result for each value of `iterable`
779
+ * @throws Error if `iterable` or `inner` is missing or does not implement `[Symbol.iterator]`, or if `outerKey`, `innerKey` or `result` is not a function
780
+ * @example
781
+ * ```ts
782
+ * const teams = [{ id: 1, name: 'a' }, { id: 2, name: 'b' }];
783
+ * const players = [{ team: 1, name: 'x' }, { team: 1, name: 'y' }];
784
+ * Array.from(Functions.groupJoin(teams, players, t => t.id, p => p.team, (t, ps) => [t.name, ps.length]));
785
+ * // [['a', 2], ['b', 0]]
786
+ * ```
787
+ * @since 0.12.0
788
+ */
789
+ declare function groupJoin<T, I, K, R>(iterable: Iterable<T>, inner: Iterable<I>, outerKey: Mapper<T, K>, innerKey: Mapper<I, K>, result: (outer: T, inners: I[]) => R): Iterable<R>;
790
+
719
791
  /**
720
792
  * Fluent wrapper over an `Iterable`: every call builds a lazy, re-runnable operations chain.
721
793
  * Transformations and taps return a new `IIterableLinq`; actions run the chain and return a result.
@@ -959,6 +1031,24 @@ export declare interface IIterableLinqBase<T> {
959
1031
  * @since 0.5.0
960
1032
  */
961
1033
  every(predicate: Predicate<T>): boolean;
1034
+ /**
1035
+ * Yields the distinct values of the chain that are not in `other`, in the order of the chain.
1036
+ * Before the first value it reads the whole `other` into a `Set`, so `other` must be finite; each run reads it again.
1037
+ * Values, or the keys returned by `keySelector`, are compared with `SameValueZero`, like `Set`: for each key the first value is yielded.
1038
+ * If `keySelector` throws, or `other` throws, the sources are closed and the error propagates.
1039
+ * @operation `Transformation`
1040
+ * @param other - the `Iterable` whose values, or keys, are left out
1041
+ * @param keySelector - called with every value of the chain and of `other`, and its index in its own source; omitted or `undefined` compares the values
1042
+ * @returns a new lazy, re-runnable chain of the distinct values that are not in `other`
1043
+ * @throws Error if `other` is missing or does not implement `[Symbol.iterator]`, or if a provided `keySelector` is not a function
1044
+ * @example
1045
+ * ```ts
1046
+ * IterableLinq.from([1, 2, 2, 3]).except([3, 4]).collectToArray(); // [1, 2]
1047
+ * IterableLinq.from([{ id: 1 }, { id: 2 }]).except([{ id: 2 }], v => v.id).collectToArray(); // [{ id: 1 }]
1048
+ * ```
1049
+ * @since 0.12.0
1050
+ */
1051
+ except<K>(other: Iterable<T>, keySelector?: Mapper<T, K>): IIterableLinq<T>;
962
1052
  /**
963
1053
  * Keeps the values accepted by a type guard and narrows their type.
964
1054
  * If `predicate` throws, the source is closed and the error propagates.
@@ -1138,6 +1228,48 @@ export declare interface IIterableLinqBase<T> {
1138
1228
  * @since 0.0.11
1139
1229
  */
1140
1230
  forEachAsync(action: AsyncAction<T>): Promise<Unit>;
1231
+ /**
1232
+ * Yields one `[key, values]` pair for each key returned by `keySelector`, in the order of the first appearance of the key;
1233
+ * the values of a group are in the order of the chain.
1234
+ * The whole chain is read before the first group is yielded, so `groupBy` does not end on an infinite chain;
1235
+ * every run reads the chain again and builds new arrays.
1236
+ * The keys are compared with `SameValueZero`, like `Map`: `NaN` is one key, `null` and `undefined` are keys too.
1237
+ * If `keySelector` throws, the source is closed and the error propagates.
1238
+ * @operation `Transformation`
1239
+ * @param keySelector - called with each value and its index; returns the key of the group of the value
1240
+ * @returns a new chain of `[key, values]` pairs
1241
+ * @throws Error if `keySelector` is not a function
1242
+ * @example
1243
+ * ```ts
1244
+ * IterableLinq.from([1, 2, 3, 4, 5]).groupBy(v => v % 2).collectToArray(); // [[1, [1, 3, 5]], [0, [2, 4]]]
1245
+ * ```
1246
+ * @since 0.12.0
1247
+ */
1248
+ groupBy<K>(keySelector: Mapper<T, K>): IIterableLinq<[K, T[]]>;
1249
+ /**
1250
+ * Yields `result(outer, inners)` for each value of the chain, with the values of `inner` that have the same key,
1251
+ * in the order of `inner`; `inners` is empty when there are none. Like LINQ `GroupJoin`.
1252
+ * Before the first value it reads the whole `inner`, so `inner` must be finite; each run reads it again.
1253
+ * The keys are compared with `SameValueZero`, like `Map`: `NaN` matches `NaN`, and `null` and `undefined` match themselves.
1254
+ * Each call of `result` gets a new array.
1255
+ * If a callback throws, or `inner` throws, the source is closed and the error propagates.
1256
+ * @operation `Transformation`
1257
+ * @param inner - the `Iterable` whose values are joined to the values of the chain
1258
+ * @param outerKey - called with each value of the chain and its index; returns its key
1259
+ * @param innerKey - called with each value of `inner` and its index; returns its key
1260
+ * @param result - called with each value of the chain and the array of its inner values; returns the value to yield
1261
+ * @returns a new chain with one result for each value of the chain
1262
+ * @throws Error if `inner` is not iterable, or if `outerKey`, `innerKey` or `result` is not a function
1263
+ * @example
1264
+ * ```ts
1265
+ * const players = [{ team: 1, name: 'x' }, { team: 1, name: 'y' }];
1266
+ * IterableLinq.from([{ id: 1, name: 'a' }, { id: 2, name: 'b' }])
1267
+ * .groupJoin(players, t => t.id, p => p.team, (t, ps) => [t.name, ps.length])
1268
+ * .collectToArray(); // [['a', 2], ['b', 0]]
1269
+ * ```
1270
+ * @since 0.12.0
1271
+ */
1272
+ groupJoin<I, K, R>(inner: Iterable<I>, outerKey: Mapper<T, K>, innerKey: Mapper<I, K>, result: (outer: T, inners: I[]) => R): IIterableLinq<R>;
1141
1273
  /**
1142
1274
  * Tells whether the chain contains `value`, compared with `SameValueZero` like `Array.prototype.includes`;
1143
1275
  * stops and closes the source at the first match.
@@ -1164,6 +1296,48 @@ export declare interface IIterableLinqBase<T> {
1164
1296
  * @since 0.6.0
1165
1297
  */
1166
1298
  indexOf(value: T): number;
1299
+ /**
1300
+ * Yields `result(outer, inner)` for each pair of a value of the chain and a value of `inner` with the same key:
1301
+ * in the order of the chain, and for each value of the chain in the order of `inner`. A value without a match yields nothing.
1302
+ * Like LINQ `Join`; named `innerJoin` because `join` is the string join of `Array.prototype`.
1303
+ * Before the first value it reads the whole `inner`, so `inner` must be finite; each run reads it again.
1304
+ * The keys are compared with `SameValueZero`, like `Map`: `NaN` matches `NaN`, and `null` and `undefined` match themselves.
1305
+ * If a callback throws, or `inner` throws, the source is closed and the error propagates.
1306
+ * @operation `Transformation`
1307
+ * @param inner - the `Iterable` whose values are joined to the values of the chain
1308
+ * @param outerKey - called with each value of the chain and its index; returns its key
1309
+ * @param innerKey - called with each value of `inner` and its index; returns its key
1310
+ * @param result - called with each pair of values with the same key; returns the value to yield
1311
+ * @returns a new chain with one result for each pair of values with the same key
1312
+ * @throws Error if `inner` is not iterable, or if `outerKey`, `innerKey` or `result` is not a function
1313
+ * @example
1314
+ * ```ts
1315
+ * const players = [{ team: 1, name: 'x' }, { team: 1, name: 'y' }];
1316
+ * IterableLinq.from([{ id: 1, name: 'a' }, { id: 2, name: 'b' }])
1317
+ * .innerJoin(players, t => t.id, p => p.team, (t, p) => `${t.name}-${p.name}`)
1318
+ * .collectToArray(); // ['a-x', 'a-y']
1319
+ * ```
1320
+ * @since 0.12.0
1321
+ */
1322
+ innerJoin<I, K, R>(inner: Iterable<I>, outerKey: Mapper<T, K>, innerKey: Mapper<I, K>, result: (outer: T, inner: I) => R): IIterableLinq<R>;
1323
+ /**
1324
+ * Yields the distinct values of the chain that are also in `other`, in the order of the chain.
1325
+ * Before the first value it reads the whole `other` into a `Set`, so `other` must be finite; each run reads it again.
1326
+ * Values, or the keys returned by `keySelector`, are compared with `SameValueZero`, like `Set`: for each key the first value is yielded.
1327
+ * If `keySelector` throws, or `other` throws, the sources are closed and the error propagates.
1328
+ * @operation `Transformation`
1329
+ * @param other - the `Iterable` whose values, or keys, are kept
1330
+ * @param keySelector - called with every value of the chain and of `other`, and its index in its own source; omitted or `undefined` compares the values
1331
+ * @returns a new lazy, re-runnable chain of the distinct values that are in `other`
1332
+ * @throws Error if `other` is missing or does not implement `[Symbol.iterator]`, or if a provided `keySelector` is not a function
1333
+ * @example
1334
+ * ```ts
1335
+ * IterableLinq.from([1, 2, 2, 3]).intersect([2, 3, 4]).collectToArray(); // [2, 3]
1336
+ * IterableLinq.from([{ id: 1 }, { id: 2 }]).intersect([{ id: 2 }], v => v.id).collectToArray(); // [{ id: 2 }]
1337
+ * ```
1338
+ * @since 0.12.0
1339
+ */
1340
+ intersect<K>(other: Iterable<T>, keySelector?: Mapper<T, K>): IIterableLinq<T>;
1167
1341
  /**
1168
1342
  * Joins the values of the chain in a string, like `Array.prototype.join`; runs the whole chain.
1169
1343
  * `null` and `undefined` become empty strings, every other value is converted with its `toString`.
@@ -1353,12 +1527,13 @@ export declare interface IIterableLinqBase<T> {
1353
1527
  * If `equals` throws, both sources are closed and the error propagates; if a source throws, the other one is closed.
1354
1528
  * @operation `Action`
1355
1529
  * @param other - the `Iterable` to compare with, for example another chain
1356
- * @param equals - called with a value of the chain and the value of `other` at the same position; defaults to `===`
1530
+ * @param equals - called with a value of the chain and the value of `other` at the same position; defaults to `SameValueZero`, like `Set` and `Map`: `NaN` equals `NaN`, `+0` equals `-0`, objects are compared by reference
1357
1531
  * @returns `true` if the two sources have the same number of values and every pair is equal
1358
1532
  * @throws Error if `other` is missing or does not implement `[Symbol.iterator]`, or if a provided `equals` is not a function
1359
1533
  * @example
1360
1534
  * ```ts
1361
1535
  * IterableLinq.from([1, 2, 3]).sequenceEqual([1, 2, 3]); // true
1536
+ * IterableLinq.from([NaN]).sequenceEqual([NaN]); // true
1362
1537
  * IterableLinq.from(['a', 'bb']).sequenceEqual(['x', 'yy'], (a, b) => a.length === b.length); // true
1363
1538
  * ```
1364
1539
  * @since 0.7.0
@@ -1628,6 +1803,24 @@ export declare interface IIterableLinqBase<T> {
1628
1803
  * @since 0.0.10
1629
1804
  */
1630
1805
  tapChainCreation(chainCreationTapper: (chain: IIterableLinq<T>) => Unit): IIterableLinq<T>;
1806
+ /**
1807
+ * Yields the distinct values of the chain, then the values of `other` not yielded yet.
1808
+ * `other` is opened only when the chain ends, so after an infinite chain it is never read; stopping early closes only the source being read.
1809
+ * Values, or the keys returned by `keySelector`, are compared with `SameValueZero`, like `Set`: for each key the first value is yielded.
1810
+ * If `keySelector` throws, the source being read is closed and the error propagates.
1811
+ * @operation `Transformation`
1812
+ * @param other - the `Iterable` read after the chain
1813
+ * @param keySelector - called with every value and its index in its own source (from 0 again for `other`); omitted or `undefined` compares the values
1814
+ * @returns a new lazy, re-runnable chain of the distinct values of the chain and of `other`
1815
+ * @throws Error if `other` is missing or does not implement `[Symbol.iterator]`, or if a provided `keySelector` is not a function
1816
+ * @example
1817
+ * ```ts
1818
+ * IterableLinq.from([1, 2, 2]).union([2, 3]).collectToArray(); // [1, 2, 3]
1819
+ * IterableLinq.from([{ id: 1 }]).union([{ id: 1 }, { id: 2 }], v => v.id).collectToArray(); // [{ id: 1 }, { id: 2 }]
1820
+ * ```
1821
+ * @since 0.12.0
1822
+ */
1823
+ union<K>(other: Iterable<T>, keySelector?: Mapper<T, K>): IIterableLinq<T>;
1631
1824
  /**
1632
1825
  * Lazily yields the values of the chain, with `value` in place of the value at `index`, like `Array.prototype.with`; a negative index counts from the end.
1633
1826
  * A non-negative index yields the values as they are read. A negative index yields each value once `-index` more values have been read,
@@ -1705,6 +1898,52 @@ declare function includes<T>(iterable: Iterable<T>, value: T): boolean;
1705
1898
  */
1706
1899
  declare function indexOf<T>(iterable: Iterable<T>, value: T): number;
1707
1900
 
1901
+ /**
1902
+ * Lazily yields `result(outer, inner)` for each pair of a value of `iterable` and a value of `inner` with the same key:
1903
+ * in the order of `iterable`, and for each outer value in the order of `inner`. An outer value without a match yields nothing.
1904
+ * Named `innerJoin` because `join` is the string join of `Array.prototype`.
1905
+ * Before the first value it reads the whole `inner`, so `inner` must be finite; each run reads it again.
1906
+ * The keys are compared with `SameValueZero`, like `Map`: `NaN` matches `NaN`, and `null` and `undefined` match themselves.
1907
+ * If a callback throws, or `inner` throws, the source is closed and the error propagates.
1908
+ * @operation `Transformation`
1909
+ * @param iterable - the source `Iterable`, the outer values
1910
+ * @param inner - the `Iterable` whose values are joined to the outer values
1911
+ * @param outerKey - called with each value of `iterable` and its index; returns its key
1912
+ * @param innerKey - called with each value of `inner` and its index; returns its key
1913
+ * @param result - called with each pair of values with the same key; returns the value to yield
1914
+ * @returns a lazy, re-runnable `Iterable` with one result for each pair of values with the same key
1915
+ * @throws Error if `iterable` or `inner` is missing or does not implement `[Symbol.iterator]`, or if `outerKey`, `innerKey` or `result` is not a function
1916
+ * @example
1917
+ * ```ts
1918
+ * const teams = [{ id: 1, name: 'a' }, { id: 2, name: 'b' }];
1919
+ * const players = [{ team: 1, name: 'x' }, { team: 1, name: 'y' }];
1920
+ * Array.from(Functions.innerJoin(teams, players, t => t.id, p => p.team, (t, p) => `${t.name}-${p.name}`));
1921
+ * // ['a-x', 'a-y']
1922
+ * ```
1923
+ * @since 0.12.0
1924
+ */
1925
+ declare function innerJoin<T, I, K, R>(iterable: Iterable<T>, inner: Iterable<I>, outerKey: Mapper<T, K>, innerKey: Mapper<I, K>, result: (outer: T, inner: I) => R): Iterable<R>;
1926
+
1927
+ /**
1928
+ * Lazily yields the distinct values of `iterable` that are also in `other`, in the order of `iterable`.
1929
+ * Before the first value it reads the whole `other` into a `Set`, so `other` must be finite; each run reads it again.
1930
+ * Values, or the keys returned by `keySelector`, are compared with `SameValueZero`, like `Set`: for each key the first value of `iterable` is yielded.
1931
+ * If `keySelector` throws, or `other` throws, the sources are closed and the error propagates.
1932
+ * @operation `Transformation`
1933
+ * @param iterable - the source `Iterable`
1934
+ * @param other - the `Iterable` whose values, or keys, are kept
1935
+ * @param keySelector - called with every value of `iterable` and of `other`, and its index in its own source; omitted or `undefined` compares the values
1936
+ * @returns a lazy, re-runnable `Iterable` of the distinct values of `iterable` that are in `other`
1937
+ * @throws Error if `iterable` or `other` is missing or does not implement `[Symbol.iterator]`, or if a provided `keySelector` is not a function
1938
+ * @example
1939
+ * ```ts
1940
+ * Array.from(Functions.intersect([1, 2, 2, 3], [2, 3, 4])); // [2, 3]
1941
+ * Array.from(Functions.intersect([{ id: 1 }, { id: 2 }], [{ id: 2 }], v => v.id)); // [{ id: 2 }]
1942
+ * ```
1943
+ * @since 0.12.0
1944
+ */
1945
+ declare function intersect<T, K>(iterable: Iterable<T>, other: Iterable<T>, keySelector?: Mapper<T, K>): Iterable<T>;
1946
+
1708
1947
  /**
1709
1948
  * The options of `fromObject` when none are given: the type of the values follows `Object.entries`.
1710
1949
  * @since 0.11.0
@@ -2134,13 +2373,14 @@ declare function reverse<T>(iterable: Iterable<T>): Iterable<T>;
2134
2373
  * @operation `Action`
2135
2374
  * @param iterable - the source `Iterable`
2136
2375
  * @param other - the `Iterable` to compare with
2137
- * @param equals - called with a value of `iterable` and the value of `other` at the same position; defaults to `===`
2376
+ * @param equals - called with a value of `iterable` and the value of `other` at the same position; defaults to `SameValueZero`, like `Set` and `Map`: `NaN` equals `NaN`, `+0` equals `-0`, objects are compared by reference
2138
2377
  * @returns `true` if the two sources have the same number of values and every pair is equal
2139
2378
  * @throws Error if `iterable` or `other` is missing or does not implement `[Symbol.iterator]`, or if a provided `equals` is not a function
2140
2379
  * @example
2141
2380
  * ```ts
2142
2381
  * Functions.sequenceEqual([1, 2, 3], [1, 2, 3]); // true
2143
2382
  * Functions.sequenceEqual([1, 2], [1, 2, 3]); // false
2383
+ * Functions.sequenceEqual([NaN], [NaN]); // true
2144
2384
  * Functions.sequenceEqual([{ id: 1 }], [{ id: 1 }], (a, b) => a.id === b.id); // true
2145
2385
  * ```
2146
2386
  * @since 0.7.0
@@ -2435,6 +2675,26 @@ declare function tapChain<T>(iterable: Iterable<T>, tapper: Tapper<Iterable<T>>)
2435
2675
  */
2436
2676
  export declare type Tapper<T> = (value: T, index: number) => Unit;
2437
2677
 
2678
+ /**
2679
+ * Lazily yields the distinct values of `iterable`, then the values of `other` not yielded yet.
2680
+ * `other` is opened only when `iterable` ends, so after an infinite source it is never read; stopping early closes only the source being read.
2681
+ * Values, or the keys returned by `keySelector`, are compared with `SameValueZero`, like `Set`: for each key the first value is yielded.
2682
+ * If `keySelector` throws, the source being read is closed and the error propagates.
2683
+ * @operation `Transformation`
2684
+ * @param iterable - the source `Iterable`
2685
+ * @param other - the `Iterable` read after the source
2686
+ * @param keySelector - called with every value and its index in its own source (from 0 again for `other`); omitted or `undefined` compares the values
2687
+ * @returns a lazy, re-runnable `Iterable` of the distinct values of `iterable` and `other`
2688
+ * @throws Error if `iterable` or `other` is missing or does not implement `[Symbol.iterator]`, or if a provided `keySelector` is not a function
2689
+ * @example
2690
+ * ```ts
2691
+ * Array.from(Functions.union([1, 2, 2], [2, 3])); // [1, 2, 3]
2692
+ * Array.from(Functions.union([{ id: 1 }], [{ id: 1 }, { id: 2 }], v => v.id)); // [{ id: 1 }, { id: 2 }]
2693
+ * ```
2694
+ * @since 0.12.0
2695
+ */
2696
+ declare function union<T, K>(iterable: Iterable<T>, other: Iterable<T>, keySelector?: Mapper<T, K>): Iterable<T>;
2697
+
2438
2698
  /**
2439
2699
  * The type with exactly one value, `unit()`: what an action or a tapper returns when it has nothing to return.
2440
2700
  * It is nominal: no other value (numbers, strings, objects, `\{\}`) is assignable to `Unit`.