/// ///Accumulate on input event, outputting the new state each time. /// public Behavior <TS> Accum <TS>(TS initState, Func <TA, TS, TS> f) { return(Transaction.Run(() => { Event <TA> ea = this; var es = new EventLoop <TS>(); Behavior <TS> s = es.Hold(initState); Event <TS> esOut = ea.Snapshot(s, f); es.Loop(esOut); return esOut.Hold(initState); })); }
/// ///Transform an event with a generalized state loop (a mealy machine). The function ///is passed the input and the old state and returns the new state and output value. /// public Event <TB> Collect <TB, TS>(TS initState, Func <TA, TS, Tuple <TB, TS> > f) { return(Transaction.Run(() => { Event <TA> ea = this; var es = new EventLoop <TS>(); Behavior <TS> s = es.Hold(initState); Event <Tuple <TB, TS> > ebs = ea.Snapshot(s, f); Event <TB> eb = ebs.Map(bs => bs.Item1); Event <TS> esOut = ebs.Map(bs => bs.Item2); es.Loop(esOut); return eb; })); }