Index and count events. More generally, pair events with any iterative value.
import { index, count } from '@most/index'
import { Stream, periodic } from '@most/core'
// 0 1 2 3 4 ...
const si: Stream<number> = index(periodic(1000))
// 1 2 3 4 5 ...
const sc: Stream<number> = count(periodic(1000))
npm install --save @most/index
Count events.
// 1 2 3 ...
count(periodic(1000))
Pair events with a 1-based count.
// [1, 'withCount'] [2, 'withCount'] [3, 'withCount'] ...
withCount(constant('withCount', periodic(1000)))
Index events.
// 0 1 2 ...
index(periodic(1000))
Pair events with a 0-based index.
// [0, 'withIndex'] [1, 'withIndex'] [2, 'withIndex'] ...
withIndex(constant('withIndex', periodic(1000)))
Pair events with a start
-based index.
// [100, 'withIndexStart'] [101, 'withIndexStart'] [102, 'withIndexStart'] ...
withIndexStart(100, constant('withIndexStart', periodic(1000)))
Pair events with any iteratively computed index.
const stringIndex = (s: string) => (prev: string): [string, string] =>
[prev, prev + s]
// ['', 'indexed'], ['a', 'indexed'], ['aa', 'indexed'], ['aaa', 'indexed']
indexed(stringIndex('a'), '', constant('indexed', periodic(1000)))