-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
It seems that many methods can be derived from the following general accumulator combinator:
accum<A>(init: Behavior<A>, fnStream: Stream<Behavior<(a: A) => A>>): Behavior<Behavior<A>>Here accum(init, fnStream) begins with init and is mapped successively through each function in the fnStream:
const accum = (init, fnStream ) => t1 => t2 =>
fnStream
.filter({ time } => (time >= t1) && (time <= t2))
.map({ value } => value(t))
.reduce((acc, feed)=>feed(acc), init(t))Now we can derive:
const stepper = (init, stream) =>
accum(Behavior.of(init), stream.map(a => Behavior.of(b => a)))
const switcher = (init, streamBeh) =>
accum(init, streamBeh.map(beh => t => a => beh(t)))
const scan = (fn, init, stream) =>
accum(Behavior.of(init), stream.map(a => Behavior.of(b => fn(a, b)))Is this correct?
paldepind, Jomik and limemloh
Metadata
Metadata
Assignees
Labels
No labels