Skip to content

jeromeludmann/async-iterable-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

async-iterable-stream

Streams for AsyncIterable.

Usage

Assuming that asyncCounter is a function that returns an AsyncIterable (like an AsyncGenerator) which can be iterated as following:

for await (const value of asyncCounter()) {
  // 1 2 3 4 5 ...
}

Import createStream from stream.ts and create a new stream around this iterable:

const counter$ = createStream(asyncCounter());

Act on this stream with operators and create a new stream from it:

const odd$ = counter$ // 1 2 3 4 5 ...
  .filter((value) => value % 2 !== 0); // 1 3 5 7 9 ...

Then create another stream of the previous:

const oddThenSquare$ = odd$ // 1 3 5 7 9 ...
  .map((value) => value ** 2); // 1 6 25 49 81 ...

And many more.

Finally, subscribe to it:

oddThenSquare$.subscribe((value) => {
  // 1 6 25 49 81 ...
});

Operators

  • map
  • filter

About

Streams for AsyncIterable like async generators

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published