Ejemplo n.º 1
0
 public static IRxVal <Tpl <A, A1, A2, A3, A4, A5> > zip <A, A1, A2, A3, A4, A5>(
     this IRxVal <A> ref1, IRxVal <A1> ref2, IRxVal <A2> ref3, IRxVal <A3> ref4, IRxVal <A4> ref5,
     IRxVal <A5> ref6
     ) => RxVal.a(
     () => F.t(ref1.value, ref2.value, ref3.value, ref4.value, ref5.value, ref6.value),
     ObservableOpImpls.zip(ref1, ref2, ref3, ref4, ref5, ref6)
     );
Ejemplo n.º 2
0
 public IRxVal <Tpl <A, B, C, D> > zip <B, C, D>(
     IRxVal <B> ref2, IRxVal <C> ref3, IRxVal <D> ref4
     )
 {
     return(zipImpl(
                ref2, ref3, ref4, RxVal.builder(() => F.t(currentValue, ref2.value, ref3.value, ref4.value))
                ));
 }
Ejemplo n.º 3
0
 public static IRxVal <Option <B> > optFlatMap <A, B>(
     this IRxVal <Option <A> > source, Fn <A, IRxVal <Option <B> > > extractor
     ) =>
 source.flatMap(aOpt =>
                aOpt.fold(
                    () => RxVal.cached(F.none <B>()),
                    extractor
                    )
                );
Ejemplo n.º 4
0
 public IRxVal <Tpl <A, A1, A2, A3, A4, A5> > zip <A1, A2, A3, A4, A5>(
     IRxVal <A1> ref2, IRxVal <A2> ref3, IRxVal <A3> ref4, IRxVal <A4> ref5, IRxVal <A5> ref6
     )
 {
     return(zipImpl(
                ref2, ref3, ref4, ref5, ref6,
                RxVal.builder(() => F.t(currentValue, ref2.value, ref3.value, ref4.value, ref5.value, ref6.value))
                ));
 }
Ejemplo n.º 5
0
        public void ctor() => describe(() => {
            var mapperInvocations        = 0;
            var actionInvocations        = 0;
            var lastActionResult         = 0;
            IRxRef <Tpl <int, int> > src = null;
            IRxVal <int> rx = null;

            beforeEach += () => {
                mapperInvocations = 0;
                actionInvocations = 0;
                src = RxRef.a(F.t(10, 0));
                rx  = new RxVal <int>(
                    -11,
                    setValue => src.subscribeWithoutEmit(tracker, t => {
                    mapperInvocations++;
                    setValue(t._1 + t._2 + 1);
                })
                    );
                rx.subscribe(tracker, i => {
                    actionInvocations++;
                    lastActionResult = i;
                });
            };

            on["creation"] = () => {
                it["should create a subscription to source"] = () => src.subscribers.shouldEqual(1);
                it["should not invoke mapper"]                = () => mapperInvocations.shouldEqual(0);
                it["should have specified value"]             = () => rx.value.shouldEqual(-11);
                it["should invoke action"]                    = () => actionInvocations.shouldEqual(1);
                it["should invoke action with current value"] = () => lastActionResult.shouldEqual(-11);

                when["source changes"] = () => {
                    beforeEach += () => src.value = F.t(2, 3);

                    it["should invoke mapper"] = () => mapperInvocations.shouldEqual(1);
                    it["should update value"]  = () => rx.value.shouldEqual(6);
                    it["should invoke action"] = () => actionInvocations.shouldEqual(2);
                    it["should invoke action with recomputed value"] = () => lastActionResult.shouldEqual(6);

                    when["source changes, but transformation result is the same"] = () => {
                        beforeEach += () => src.value = F.t(3, 2);

                        it["should invoke mapper"]       = () => mapperInvocations.shouldEqual(2);
                        it["should keep the value same"] = () => rx.value.shouldEqual(6);
                        it["should not invoke action"]   = () => actionInvocations.shouldEqual(2);
                    };
                };
            };
        });
Ejemplo n.º 6
0
 public static IRxVal <B> map <A, B>(this IRxVal <A> rx, Fn <A, B> mapper) =>
 RxVal.a(() => mapper(rx.value), ObservableOpImpls.map(rx, mapper));
Ejemplo n.º 7
0
 public static IRxVal <Tpl <A, B, C, D, E> > zip <A, B, C, D, E>(
     this IRxVal <A> ref1, IRxVal <B> ref2, IRxVal <C> ref3, IRxVal <D> ref4, IRxVal <E> ref5
     ) => RxVal.a(
     () => F.t(ref1.value, ref2.value, ref3.value, ref4.value, ref5.value),
     ObservableOpImpls.zip(ref1, ref2, ref3, ref4, ref5)
     );
Ejemplo n.º 8
0
 public static IRxVal <Tpl <A, B, C> > zip <A, B, C>(
     this IRxVal <A> rx, IRxVal <B> rx2, IRxVal <C> rx3
     ) => RxVal.a(
     () => F.t(rx.value, rx2.value, rx3.value),
     ObservableOpImpls.zip(rx, rx2, rx3)
     );
Ejemplo n.º 9
0
 public static IRxVal <A> filter <A>(this IRxVal <A> rx, Fn <A, bool> predicate, A onFiltered) =>
 rx.map(RxVal.filterMapper(predicate, onFiltered));
Ejemplo n.º 10
0
 // Convert this observable to reactive value with given initial value.
 public static IRxVal <A> toRxVal <A>(this IObservable <A> o, A initial) =>
 RxVal.a(initial, o.subscribe);
Ejemplo n.º 11
0
 public static IRxVal <Option <A> > extract <A>(this Option <IRxVal <A> > rxOpt) =>
 rxOpt.fold(RxVal.cached(F.none <A>()), val => val.map(a => a.some()));
Ejemplo n.º 12
0
 public static IRxVal <Option <B> > optFlatMap <A, B>(
     this IRxVal <Option <A> > source, Fn <A, Option <IRxVal <Option <B> > > > extractor
     ) =>
 source.flatMap(aOpt =>
                aOpt.flatMap(extractor).getOrElse(RxVal.cached(F.none <B>()))
                );
Ejemplo n.º 13
0
 public IRxVal <Tpl <A, B> > zip <B>(IRxVal <B> ref2)
 {
     return(zipImpl(ref2, RxVal.builder(() => F.t(currentValue, ref2.value))));
 }
Ejemplo n.º 14
0
 public IRxVal <A> filter(Fn <A, bool> predicate, A onFiltered)
 {
     return(map(RxVal.filterMapper(predicate, onFiltered)));
 }
Ejemplo n.º 15
0
 public IRxVal <B> flatMap <B>(Fn <A, IRxVal <B> > mapper)
 {
     return(flatMapImpl(mapper, RxVal.builder(() => mapper(currentValue).value)));
 }
Ejemplo n.º 16
0
 public new IRxVal <B> map <B>(Fn <A, B> mapper)
 {
     return(mapImpl(mapper, RxVal.builder(() => mapper(currentValue))));
 }