Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/staltz/callbag-to-iterable

👜 Convert a synchronous pullable callbag source to an Iterable
https://github.com/staltz/callbag-to-iterable

Last synced: 28 days ago
JSON representation

👜 Convert a synchronous pullable callbag source to an Iterable

Awesome Lists containing this project

README

        

# callbag-to-iterable

Convert a synchronous pullable callbag source to an Iterable.

`npm install callbag-to-iterable`

## example

Convert an Iterable to a synchronous pullable callbag, apply some operators, then convert back to Iterable and consume it with a `for of` loop:

```js
const {forEach, fromIter, take, map, pipe} = require('callbag-basics');
const toIterable = require('callbag-to-iterable');

function* range(from, to) {
let i = from;
while (i <= to) {
yield i;
i++;
}
}

const result = pipe(
fromIter(range(40, 99)), // 40, 41, 42, 43, 44, 45, 46, ...
take(5), // 40, 41, 42, 43, 44
map(x => x / 4), // 10, 10.25, 10.5, 10.75, 11
toIterable
);

for (let x of result) {
console.log(x)
}
// 10
// 10.25
// 10.5
// 10.75
// 11
```