An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

## Rex

![rex-with-border@2x](https://github.com/user-attachments/assets/f2dbe8c0-052b-417b-bf7b-efef108ecbe4)

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');
},
});
```