Esempio n. 1
0
 ///
 ///Transform a behavior 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 Behavior <TB> Collect <TB, TS>(TS initState, Func <TA, TS, Tuple <TB, TS> > f)
 {
     return(Transaction.Run(() =>
     {
         Event <TA> ea = Updates().Coalesce((fst, snd) => snd);
         Func <Tuple <TB, TS> > zbs = () => f(SampleNoTrans(), initState);
         var ebs = new EventLoop <Tuple <TB, TS> >();
         Behavior <Tuple <TB, TS> > bbs = ebs.HoldLazy(zbs);
         Behavior <TS> bs = bbs.Map((x => x.Item2));
         Event <Tuple <TB, TS> > ebsOut = ea.Snapshot(bs, f);
         ebs.Loop(ebsOut);
         return bbs.Map(x => x.Item1);
     }));
 }