当前位置: 首页>>代码示例>>C#>>正文


C# Event.Map方法代码示例

本文整理汇总了C#中Event.Map方法的典型用法代码示例。如果您正苦于以下问题:C# Event.Map方法的具体用法?C# Event.Map怎么用?C# Event.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Event的用法示例。


在下文中一共展示了Event.Map方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Accumulate

 public static Behavior<double> Accumulate(
         Event<Unit> eClearAccumulator,
         Event<int> ePulses,
         Behavior<double> calibration) {
     BehaviorLoop<int> total = new BehaviorLoop<int>();
     total.Loop(ePulses.Snapshot(total,
         (pulses_, total_) => pulses_ + total_)
            .Merge(eClearAccumulator.Map(f => 0))
            .Hold(0));
     return Behavior<double>.Lift(
         (total_, calibration_) => total_ * calibration_,
         total, calibration);
 }
开发者ID:davideGiovannini,项目名称:sodium,代码行数:13,代码来源:AccumulatePulsesPump.cs

示例2: Form1

        public Form1()
        {
            InitializeComponent();

            startBtn.Click += (o, s) => runningEvent.Fire(true);

            stopBtn.Click += (o, s) =>
            {
                degreesSignal.Stop();
                runningEvent.Fire(false);
            };

            frequency.ValueChanged += (o, s) => intervalChanged.Fire(frequency.Value);

            degreesSignal = new Signal<double>(new AutoDouble(0.0, 0.001), Frequency.Hz(0.0), this.CreateDispatcher());
            degreesSignal.Subscribe(SetDegValue);

            signalTickCount = degreesSignal.Snapshot(new AutoLong());
            signalTickCount.Subscribe(SetTickCount);

            radiansSignal = degreesSignal.Map(d => d * RadsPerDeg);
            radiansSignal.Subscribe(SetRadValue);

            sineSignal = radiansSignal.Map(Math.Sin);
            sineSignal.Subscribe(SetSinValue);

            cosineSignal = radiansSignal.Map(Math.Cos);
            cosineSignal.Subscribe(SetCosValue);

            runningEvent = new FirableEvent<bool>();
            runningEvent.Subscribe(r => { degreesSignal.Running = r; });

            runningBehavior = runningEvent.Hold(false);
            runningBehavior.SubscribeWithInitialFire(EnableControls);

            intervalChanged = new FirableEvent<decimal>();
            intervalBehavior = intervalChanged.Hold(frequency.Value);
            intervalBehavior.Map(Frequency.Hz).SubscribeWithInitialFire(FrequencyChanged);
        }
开发者ID:jerometerry,项目名称:potassium,代码行数:39,代码来源:Form1.cs

示例3: NotifyPointOfSale

 public NotifyPointOfSale(
   LifeCycle lc,
   Event<Unit> eClearSale,
   Fill fi)
 {
   Behavior<Boolean> locked = lc.EStart.Map(u => true).Merge(eClearSale.Map(u => false)).Hold(false);
   EStart = lc.EStart.Gate(locked.Map(l => !l));
   EEnd = lc.EEnd.Gate(locked);
   FuelFlowing = EStart.Map(f => Optional<Fuel>.Of(f))
     .Merge(EEnd.Map(f => Optional<Fuel>.Empty())).Hold(Optional<Fuel>.Empty());
   FillActive = EStart.Map(f => Optional<Fuel>.Of(f))
     .Merge(eClearSale.Map(f => Optional<Fuel>.Empty())).Hold(Optional<Fuel>.Empty());
   EBeep = eClearSale;
   ESaleComplete = Event<Sale>.FilterOptional(
     EEnd.Snapshot(
       Behavior<Sale>.Lift(
         (oFuel, price_, dollars, liters) => oFuel.IsPresent ? Optional<Sale>.Of(new Sale(oFuel.Get(), price_, dollars, liters)) : Optional<Sale>.Empty(),
         FuelFlowing,
         fi.Price,
         fi.DollarsDelivered,
         fi.LitersDelivered)));
 }
开发者ID:davideGiovannini,项目名称:sodium,代码行数:22,代码来源:NotifyPointOfSale.cs

示例4: Keypad

 public Keypad(Event<Key> eKeypad, Event<Unit> eClear)
 {
   BehaviorLoop<int> value = new BehaviorLoop<int>();
   this.Value = value;
   Event<int> eKeyUpdate = Event<int>.FilterOptional(
     eKeypad.Snapshot(
       value,
       (key, value_) =>
       {
         if (key == Key.CLEAR)
           return Optional<int>.Of(0);
         else
         {
           int x10 = value_ * 10;
           return x10 >= 1000
             ? Optional<int>.Empty()
             : Optional<int>.Of(
               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
               );
         }
       })
     );
   value.Loop(
     eKeyUpdate.Merge(eClear.Map(u => 0))
       .Hold(0));
   EBeep = eKeyUpdate.Map(k => Unit.UNIT);
 }
开发者ID:davideGiovannini,项目名称:sodium,代码行数:45,代码来源:KeyPad.cs

示例5: InitializeMouseHandler

        private void InitializeMouseHandler()
        {
            mouseButtonEvent = new FirableEvent<MouseStatus>();
            mouseMoveEvent = new FirableEvent<MouseEventArgs>();
            mouseButtonBehavior = mouseButtonEvent.Hold(MouseStatus.Up);
            this.mouseButtonDown = new EqualityPredicate<MouseStatus>(mouseButtonBehavior,  MouseStatus.Down);
            mouseDragEvent = mouseMoveEvent.Gate(this.mouseButtonDown);
            mouseButtonBehavior.SubscribeWithInitialFire(a =>
            {
                status.Text = string.Format("{0} {1}", a, DateTime.Now);
            });

            mouseDragEvent.Map(e => new Tuple<string, string>(e.X.ToString(), e.Y.ToString())).Subscribe(t =>
            {
                x.Text = t.Item1;
                y.Text = t.Item2;
            });

            MouseMove += (s, e) => mouseMoveEvent.Fire(e);
            MouseDown += (s, e) => mouseButtonEvent.Fire(MouseStatus.Down);
            MouseUp += (s, e) => mouseButtonEvent.Fire(MouseStatus.Up);
        }
开发者ID:jerometerry,项目名称:potassium,代码行数:22,代码来源:Form1.cs

示例6: LifeCycle

 public LifeCycle(Event<UpDown> eNozzle1,
                  Event<UpDown> eNozzle2,
                  Event<UpDown> eNozzle3) 
 {
     Event<Fuel> eLiftNozzle = WhenLifted(eNozzle1, Fuel.ONE).Merge(
                               WhenLifted(eNozzle2, Fuel.TWO).Merge(
                               WhenLifted(eNozzle3, Fuel.THREE)));
     BehaviorLoop<Optional<Fuel>> fillActive = new BehaviorLoop<Optional<Fuel>>();
     this.FillActive = fillActive;
     this.EStart = Event<Fuel>.FilterOptional(
         eLiftNozzle.Snapshot(fillActive, (newFuel, fillActive_) =>
             fillActive_.IsPresent ? Optional<Fuel>.Empty()
                                   : Optional<Fuel>.Of(newFuel)));
     this.EEnd = WhenSetDown(eNozzle1, Fuel.ONE, fillActive).Merge(
                 WhenSetDown(eNozzle2, Fuel.TWO, fillActive).Merge(
                 WhenSetDown(eNozzle3, Fuel.THREE, fillActive)));
   fillActive.Loop(
     EStart.Map(f => Optional<Fuel>.Of(f))
       .Merge(EEnd.Map(e => Optional<Fuel>.Empty()))
               .Hold(Optional<Fuel>.Empty())
     );
 }
开发者ID:davideGiovannini,项目名称:sodium,代码行数:22,代码来源:LifeCycle.cs


注:本文中的Event.Map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。