Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Andarist/callbag-loop
π Callbag operator that accumulates results using a feedback loop that emits one value and feeds back another to be used in the next iteration.
https://github.com/Andarist/callbag-loop
callbag callbags
Last synced: 16 days ago
JSON representation
π Callbag operator that accumulates results using a feedback loop that emits one value and feeds back another to be used in the next iteration.
- Host: GitHub
- URL: https://github.com/Andarist/callbag-loop
- Owner: Andarist
- Created: 2018-05-04T08:44:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-07T22:19:43.000Z (about 6 years ago)
- Last Synced: 2024-10-20T06:22:55.886Z (22 days ago)
- Topics: callbag, callbags
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-callbags - loop
README
# callbag-loop
Callbag operator that accumulates results using a feedback loop that emits one value and feeds back another to be used in the next iteration.
It allows you to maintain and update a βstateβ (a.k.a. feedback, a.k.a. seed for the next iteration) while emitting a different value. In contrast, [scan](https://github.com/staltz/callbag-scan) feeds back and produces the same value.
Inspired by [most.js's loop](https://mostcore.readthedocs.io/en/latest/api.html#loop).
## Example
```js
import forEach from 'callbag-for-each'
import fromIter from 'callbag-from-iter'
import loop from 'callbag-loop'
import pipe from 'callbag-pipe'const add = (a, b) => a + b
const average = values => values.reduce(add, 0) / values.lengthpipe(
fromIter([10, 20, 60, 20, 5, 150, 3, 80]),
loop((seed, value) => {
seed.push(value)
seed = seed.slice(-4)
return [seed, average(seed)]
}, []),
forEach(avg => {
// will log 10, 15, 30, 27.5, 26.25, 58.75, 44.5, 59.5
console.log(avg)
}),
)
```