https://github.com/tauseefk/rex
Everything is streams.
https://github.com/tauseefk/rex
functional-programming stream
Last synced: 2 months ago
JSON representation
Everything is streams.
- Host: GitHub
- URL: https://github.com/tauseefk/rex
- Owner: tauseefk
- License: mit
- Created: 2025-02-04T05:32:44.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-14T02:21:33.000Z (9 months ago)
- Last Synced: 2025-07-24T09:19:32.248Z (8 months ago)
- Topics: functional-programming, stream
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/rextream
- Size: 85 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Rex

Tiny arms but bytes.
#### Create a stream and subscribe
```typescript
// - `Stream.fromInterval(100)` creates a stream that emits a value every 100 milliseconds.
// - `skipN(10)` creates a filter that allows only every 10th value to pass through.
const $oneSecStream = Stream.fromInterval(100).filter(skipN(10));
// - The stream will print emitted values until the emitted value is 50, then unsubscribes.
// - Once unsubscribed or naturally completed, the completion handler is executed.
$oneSecStream.subscribe({
next: (tick) => {
console.log(tick);
if (tick >= 50) $oneSecStream.unsubscribe?.();
},
complete: () => {
console.log('stream concluded');
},
});
```
#### Combine two streams
```typescript
// Emit a tuple of values every 500 millisecond
//
// - `Stream.fromInterval(500)` creates a stream that emits a value every 500 milliseconds.
// - `Stream.fromInterval(1000)` creates a stream that emits a value every 1 second.
// - withLatestFrom combines both the Streams.
const $halfSecStream = Stream.fromInterval(500);
const $mixedTimerStream =
Stream.fromInterval(1000).withLatestFrom($halfSecStream);
$mixedTimerStream.subscribe({
next: ([halfSecTick, oneSecTick]) => {
console.log(halfSecTick, oneSecTick);
if (halfSecTick >= 5) $mixedTimerStream.unsubscribe?.();
},
complete: () => {
console.log('stream concluded');
},
});
```