Example #1
0
            private static Cell <double> PausableClock(Stream <Unit> sPause, Stream <Unit> sResume, Cell <double> clock)
            {
                Cell <IMaybe <double> > pauseTime = sPause.Snapshot(clock, (_, t) => Maybe.Just(t)).OrElse(sResume.Map(_ => Maybe.Nothing <double>())).Hold(Maybe.Nothing <double>());
                Cell <double>           lostTime  = sResume.Accum(0.0, (_, total) =>
                {
                    double tPause = pauseTime.Sample().Match(v => v, () => 0);
                    double now    = clock.Sample();
                    return(total + (now - tPause));
                });

                return(pauseTime.Lift(clock, lostTime, (otPause, tClk, tLost) => otPause.Match(v => v, () => tClk) - tLost));
            }
Example #2
0
        public static Cell <Signal> Integrate(Cell <Signal> sig, double initial)
        {
            Stream <Signal> sSig = Operational.Updates(sig);

            return(sSig.Accum(sig.Sample().Integrate(initial), (n, o) => n.Integrate(o.ValueAt(n.T0))));
        }
Example #3
0
        public static DiscreteCell <Signal> Integrate(DiscreteCell <Signal> sig, double initial)
        {
            Stream <Signal> sSig = sig.Updates;

            return(sSig.Accum(sig.Cell.Sample().Integrate(initial), (n, o) => n.Integrate(o.ValueAt(n.T0))));
        }