Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/staltz/callbag-take
👜 Callbag operator that limits the total amount of data sent through
https://github.com/staltz/callbag-take
Last synced: 5 days ago
JSON representation
👜 Callbag operator that limits the total amount of data sent through
- Host: GitHub
- URL: https://github.com/staltz/callbag-take
- Owner: staltz
- License: mit
- Created: 2018-01-29T10:50:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-08-03T06:33:55.000Z (over 1 year ago)
- Last Synced: 2024-12-22T00:39:18.085Z (23 days ago)
- Language: JavaScript
- Homepage:
- Size: 21.5 KB
- Stars: 7
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-callbags - take
README
# callbag-take
Callbag operator that limits the amount of data sent by a source. Works on either pullable and listenable sources.
`npm install callbag-take`
## example
On a listenable source:
```js
const interval = require('callbag-interval');
const forEach = require('callbag-for-each');
const take = require('callbag-take');const source = take(3)(interval(1000));
forEach(x => console.log(x))(source); // 0
// 1
// 2
```On a pullable source:
```js
const fromIter = require('callbag-from-iter');
const forEach = require('callbag-for-each');
const take = require('callbag-take');function* range(from, to) {
let i = from;
while (i <= to) {
yield i;
i++;
}
}const source = take(4)(fromIter(range(100, 999)));
forEach(x => console.log(x))(source); // 100
// 101
// 102
// 103
```