https://github.com/vilicvane/rxjs-branch
Branch operator for RxJS.
https://github.com/vilicvane/rxjs-branch
rxjs
Last synced: 4 months ago
JSON representation
Branch operator for RxJS.
- Host: GitHub
- URL: https://github.com/vilicvane/rxjs-branch
- Owner: vilicvane
- License: mit
- Created: 2024-03-10T16:14:31.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-11T21:52:58.000Z (over 1 year ago)
- Last Synced: 2025-03-24T00:54:54.537Z (4 months ago)
- Topics: rxjs
- Language: TypeScript
- Homepage:
- Size: 69.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/rxjs-branch)
[](./package.json)
[](./LICENSE)
[](https://discord.gg/wEVn2qcf8h)# Branch Operator for RxJS
## Installation
```sh
npm install rxjs-branch
```## Usage
```ts
const branches = await firstValueFrom(
range(0, 10).pipe(
branch(
value => value % 2 === 0,
(state, value) => state,
),
mergeMap(value$ =>
value$.pipe(
map(([state, value]) => value),
toArray(),
),
),
toArray(),
),
);expect(branches).toEqual([
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[2, 3, 4, 5, 6, 7, 8, 9],
[4, 5, 6, 7, 8, 9],
[6, 7, 8, 9],
[8, 9],
]);
```## License
MIT License.