Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/staltz/callbag-to-iterable
- Owner: staltz
- License: mit
- Created: 2018-02-08T18:55:54.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-08T18:56:05.000Z (almost 7 years ago)
- Last Synced: 2024-10-10T00:49:14.516Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-callbags - to-iterable
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
```