Example #1
0
        public static Cell<double> CapturePrice(
            Stream<Fuel> sStart,
            Cell<double> price1, Cell<double> price2,
            Cell<double> price3)
        {
            Stream<double> sPrice1 = sStart.Snapshot(price1,
                (f, p) => f == Fuel.One ? Maybe.Just(p) : Maybe.Nothing<double>()).FilterMaybe();
            Stream<double> sPrice2 = sStart.Snapshot(price2,
                (f, p) => f == Fuel.Two ? Maybe.Just(p) : Maybe.Nothing<double>()).FilterMaybe();
            Stream<double> sPrice3 = sStart.Snapshot(price3,
                (f, p) => f == Fuel.Three ? Maybe.Just(p) : Maybe.Nothing<double>()).FilterMaybe();

            return sPrice1.OrElse(sPrice2.OrElse(sPrice3)).Hold(0.0);
        }
Example #2
0
 public Keypad(Stream<Key> sKeypad, Stream<Unit> sClear)
 {
     CellLoop<int> value = new CellLoop<int>();
     this.Value = value;
     Stream<int> sKeyUpdate = sKeypad.Snapshot(value, (key, valueLocal) =>
     {
         if (key == Key.Clear)
         {
             return Maybe.Just(0);
         }
         int x10 = valueLocal * 10;
         return x10 >= 1000
             ? Maybe.Nothing<int>()
             : Maybe.Just(
                 key == Key.Zero ? x10 :
                     key == Key.One ? x10 + 1 :
                         key == Key.Two ? x10 + 2 :
                             key == Key.Three ? x10 + 3 :
                                 key == Key.Four ? x10 + 4 :
                                     key == Key.Five ? x10 + 5 :
                                         key == Key.Six ? x10 + 6 :
                                             key == Key.Seven ? x10 + 7 :
                                                 key == Key.Eight ? x10 + 8 :
                                                     x10 + 9);
     }).FilterMaybe();
     value.Loop(sKeyUpdate.OrElse(sClear.Map(u => 0)).Hold(0));
     this.SBeep = sKeyUpdate.Map(_ => Unit.Value);
 }
Example #3
0
 public static Cell<double> Accumulate(
     Stream<Unit> sClearAccumulator,
     Stream<int> sPulses,
     Cell<double> calibration)
 {
     CellLoop<int> total = new CellLoop<int>();
     total.Loop(sClearAccumulator.Map(u => 0)
         .OrElse(sPulses.Snapshot(total, (pulsesLocal, totalLocal) => pulsesLocal + totalLocal))
         .Hold(0));
     return total.Lift(
         calibration,
         (totalLocal, calibrationLocal) => totalLocal * calibrationLocal);
 }
Example #4
0
 private static Stream<End> WhenSetDown(Stream<UpDown> sNozzle, Fuel nozzleFuel, Cell<IMaybe<Fuel>> fillActive)
 {
     return sNozzle.Snapshot(fillActive, (u, f) => u == UpDown.Down && f.Equals(Maybe.Just(nozzleFuel)) ? Maybe.Just(End.Value) : Maybe.Nothing<End>()).FilterMaybe();
 }