Esempio n. 1
0
 public static IRxVal <B> map <A, B>(this IRxVal <A> src, Fn <A, B> mapper) =>
 new RxVal <B>(
     mapper(src.value),
     setValue => src.subscribeWithoutEmit(
         NoOpDisposableTracker.instance, a => setValue(mapper(a))
         )
     );
Esempio n. 2
0
 public static IRxVal <R> zip <A1, A2, R>(
     this IRxVal <A1> a1Src, IRxVal <A2> a2Src, Fn <A1, A2, R> zipper
     ) =>
 new RxVal <R>(
     zipper(a1Src.value, a2Src.value),
     setValue => {
     var tracker = NoOpDisposableTracker.instance;
     var a1Sub   = a1Src.subscribeWithoutEmit(tracker, a1 => setValue(zipper(a1, a2Src.value)));
     var a2Sub   = a2Src.subscribeWithoutEmit(tracker, a2 => setValue(zipper(a1Src.value, a2)));
     return(a1Sub.join(a2Sub));
 }
     );
Esempio n. 3
0
        public static IRxVal <B> flatMap <A, B>(this IRxVal <A> src, Fn <A, IRxVal <B> > mapper)
        {
            var bRx = mapper(src.value);

            return(new RxVal <B>(
                       bRx.value,
                       setValue => {
                var tracker = NoOpDisposableTracker.instance;
                var subToBRx = bRx.subscribeWithoutEmit(tracker, b => setValue(b));

                var aSub = src.subscribeWithoutEmit(
                    tracker,
                    a => {
                    subToBRx.unsubscribe();
                    bRx = mapper(a);
                    setValue(bRx.value);
                    subToBRx = bRx.subscribeWithoutEmit(tracker, b => setValue(b));
                }
                    );
                return aSub.andThen(() => subToBRx.unsubscribe());
            }
                       ));
        }