diff --git a/README.md b/README.md index 5031f66..29f6476 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ const pipe = createPipe( const result1 = pipe([1, 1, 2, 2, 3, 4, 5]); // 14 const result2 = pipe([1, 1, 1, 2, 2, 2]); // 5 +// Async example const asyncPipe = createPipe( set.distinctAsync, (input) => single.mapAsync(input, (x) => x**2), @@ -81,6 +82,16 @@ const asyncPipe = createPipe( ); const result3 = await asyncPipe([1, 1, 2, 2, 3, 4, 5].map((x) => Promise.resolve(x))); // 14 const result4 = await asyncPipe([1, 1, 1, 2, 2, 2].map((x) => Promise.resolve(x))); // 5 + +// Another way to create pipes +const anotherPipe = createPipe() + .add(set.distinct) + .add((input) => single.map(input, (x) => x**2)) + .add((input) => single.filter(input, (x) => x < 10)) + .add(reduce.toSum); + +const result5 = anotherPipe([1, 1, 2, 2, 3, 4, 5]); // 14 +const result6 = anotherPipe([1, 1, 1, 2, 2, 2]); // 5 ``` [More about Pipes](#Pipes) diff --git a/tests/examples/pipe.test.ts b/tests/examples/pipe.test.ts index e288984..6d7fbe2 100644 --- a/tests/examples/pipe.test.ts +++ b/tests/examples/pipe.test.ts @@ -43,8 +43,9 @@ it("Pipe Usage Example Test", () => { } }); -it("Chained Pipe Usage Example Test", () => { - const pipe = createPipe(set.distinct) +it("Chain Pipe Usage Example Test", () => { + const pipe = createPipe() + .add(set.distinct) .add((input) => single.map(input, (x) => x**2)) .add((input) => single.filter(input, (x) => x < 10)) .add(reduce.toSum); @@ -64,9 +65,8 @@ it("Chained Pipe Usage Example Test", () => { } }); -it("Another Chain Pipe Usage Example Test", () => { - const pipe = createPipe() - .add(set.distinct) +it("Another Chained Pipe Usage Example Test", () => { + const pipe = createPipe(set.distinct) .add((input) => single.map(input, (x) => x**2)) .add((input) => single.filter(input, (x) => x < 10)) .add(reduce.toSum);