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)) ) );
public StandardBannerAggregator( ImmutableList <IStandardBannerKnowsState> banners ) { this.banners = banners; hasAd = banners.Select(_ => _.hasAd).anyOf(); }
public SingleItemLoader() { itemState = currentLoader.flatMap(opt => { discardPreviousRequest(); foreach (var bindingLoader in opt) { var(_request, assetFtr) = bindingLoader.loadASync(); request.value = _request.some(); return(assetFtr.toRxVal().map(csOpt => csOpt.toRight(new IsLoading(true)))); } return(RxVal.cached(F.left <IsLoading, A>(new IsLoading(false)))); }); itemState.subscribe(tracker, e => { if (e.isRight) { discardPreviousRequest(); } }); currentLoader.zip(priority, request, (show, _priority, req) => F.t(show.isSome ? (_priority == LoadPriority.High ? PRIORITY_HIGH : PRIORITY_LOW) : PRIORITY_OFF, req) ).subscribe(tracker, tpl => { var(_priority, req) = tpl; foreach (var r in req) { r.priority = _priority; } }); }
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) );
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)) )); }
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 ) );
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)) )); }
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)); } );
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); }; }; }; });
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()); } )); }
public static IRxVal <B> map <A, B>(this IRxVal <A> rx, Fn <A, B> mapper) => RxVal.a(() => mapper(rx.value), ObservableOpImpls.map(rx, mapper));
public IRxVal <Tpl <A, B> > zip <B>(IRxVal <B> ref2) { return(zipImpl(ref2, RxVal.builder(() => F.t(currentValue, ref2.value)))); }
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) );
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) );
[PublicAPI] public static IRxVal <Option <B> > mapT <A, B>( this IRxVal <Option <A> > rxMaybeA, Fn <A, B> f ) => rxMaybeA.map(maybeA => maybeA.map(f));
public static IRxVal <A> filter <A>(this IRxVal <A> rx, Fn <A, bool> predicate, A onFiltered) => rx.map(RxVal.filterMapper(predicate, onFiltered));
// TODO: test /// <summary> /// Convert <see cref="IRxVal{A}"/> to <see cref="IObservable{B}"/>. /// /// Useful for converting from <see cref="IRxVal{A}"/> to event source. For example: /// /// <code><![CDATA[ /// someRxVal.map(_ => F.unit) /// ]]></code> /// /// would only emit one event, because the result of a map would be a <see cref="IRxVal{A}"/> /// that has a <see cref="Unit"/> type, which by it's definition only has one value. /// /// Thus we'd need to use /// <code><![CDATA[ /// someRxVal.toEventSource(_ => F.unit) /// ]]></code> /// </summary> public static IObservable <B> toEventSource <A, B>( this IRxVal <A> rxVal, Fn <A, B> mapper ) => new Observable <B>(onEvent => rxVal.subscribe(NoOpDisposableTracker.instance, v => onEvent(mapper(v))) );
public static IObservable <Unit> toEventSource <A>(this IRxVal <A> o) => o.toEventSource(_ => F.unit);
public static IRxVal <Option <B> > optFlatMap <A, B>( this IRxVal <Option <A> > source, Fn <A, IRxVal <B> > extractor ) => source.optFlatMap(a => extractor(a).map(b => b.some()));
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>())) );
public static IRxVal <Option <B> > optMap <A, B>( this IRxVal <Option <A> > source, Fn <A, B> mapper ) => source.map(aOpt => aOpt.map(mapper));