Skip to content

Commit 3a97a07

Browse files
committed
New release: Pipe.add() method added.
1 parent 97238af commit 3a97a07

8 files changed

+1279
-85
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# IterTools Typescript Change Log
22

3+
## v1.29.0 - 2024-12-24
4+
5+
### New features
6+
* Pipe
7+
* `add()`
8+
39
## v1.28.1 - 2024-12-23
410

511
Documentation fixed.

Diff for: README.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -3553,7 +3553,11 @@ type PipeOperationSequence<TFlow extends any[]> =
35533553
TFlow extends [infer T1, infer T2, ...infer Rest]
35543554
? [PipeOperation<T1, T2>, ...PipeOperationSequence<[T2, ...Rest]>]
35553555
: [];
3556-
type Pipe<TFlow extends any[]> = PipeOperation<First<TFlow>, Last<TFlow>>
3556+
type Pipe<TFlow extends any[]> = PipeOperation<First<TFlow>, Last<TFlow>> & {
3557+
add: TFlow extends []
3558+
? <TInput, TOutput>(operation: PipeOperation<TInput, TOutput>) => Pipe<[TInput, TOutput]>
3559+
: <T>(operation: PipeOperation<Last<TFlow>, T>) => Pipe<[...TFlow, T]>;
3560+
};
35573561
```
35583562

35593563
Pipe creation function:
@@ -3601,6 +3605,28 @@ const result1 = pipe([1, 1, 2, 2, 3, 4, 5]); // 14
36013605
const result2 = pipe([1, 1, 1, 2, 2, 2]); // 5
36023606
```
36033607

3608+
Example with creating pipe using chain calls:
3609+
```typescript
3610+
import { createPipe } from "itertools-ts";
3611+
3612+
const pipe = createPipe()
3613+
.add(set.distinct<number>)
3614+
.add((input) => single.map(input, (x) => x**2))
3615+
.add((input) => single.filter(input, (x) => x < 10))
3616+
.add(reduce.toSum);
3617+
3618+
const result1 = pipe([1, 1, 2, 2, 3, 4, 5]); // 14
3619+
const result2 = pipe([1, 1, 1, 2, 2, 2]); // 5
3620+
3621+
// You can create a new pipe adding some operations
3622+
const extendedPipe = pipe
3623+
.add((x) => x * 2)
3624+
.add((x) => x + 1);
3625+
3626+
const result3 = extendedPipe([1, 1, 2, 2, 3, 4, 5]); // 29
3627+
const result4 = extendedPipe([1, 1, 1, 2, 2, 2]); // 11
3628+
```
3629+
36043630
Asynchronous pipe example:
36053631
```typescript
36063632
import { createPipe } from "itertools-ts";
@@ -3624,6 +3650,10 @@ const result1 = await asyncPipe(asyncInput1); // 14
36243650
// You can reuse the pipe
36253651
const asyncInput2 = [1, 1, 1, 2, 2, 2].map((x) => Promise.resolve(x));
36263652
const result4 = await asyncPipe(asyncInput2); // 5
3653+
3654+
// You can create a new pipe adding some asynchronous operations
3655+
const extendedAsyncPipe = asyncPipe.add(async (x) => (await x) * 2);
3656+
const result5 = await extendedAsyncPipe(asyncInput2); // 10
36273657
```
36283658

36293659
You can also use pipe for non-iterables:

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "itertools-ts",
3-
"version": "1.28.1",
3+
"version": "1.29.0",
44
"description": "Extended itertools port for TypeScript and JavaScript. Provides a huge set of functions for working with iterable collections (including async ones)",
55
"license": "MIT",
66
"repository": {
File renamed without changes.

0 commit comments

Comments
 (0)