ReactiveX/Rx.NET 中 RxJS switchMap 的等价物
Equivalent of RxJS switchMap in ReactiveX/Rx.NET
在 RxJS 中,有一个 switchMap function. Is there an equivalent in ReactiveX/Rx.NET? I don't see one in the transforming 文档。
编辑
switch
是等价的。 http://reactivex.io/documentation/operators/switch.html
简而言之,switchMap
和 switch
将取消所有之前的流,而 flatMap
不会。
Rx.NET 中没有单个 SwitchMany 相当于 Rx.js 中的 switchMap。您需要使用单独的 Select 和 Switch 函数。
Observable.Interval(TimeSpan.FromMinutes(1))
.Select(_ => Observable.Return(10))
.Switch()
文档:https://msdn.microsoft.com/en-us/library/hh229197(v=vs.103).aspx
来自http://reactivex.io/documentation/operators/switch.html
Switch operator subscribes to an Observable that emits
Observables. Each time it observes one of these emitted Observables,
the Observable returned by Switch unsubscribes from the
previously-emitted Observable begins emitting items from the latest
Observable.
作为MorleyDev pointed, the .NET implementation is https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh229197(v=vs.103),所以
Rx.NET 中 RxJS switchMap 的等价物是 Switch 和 Select 运算符的组合:
// RxJS
observableOfObservables.pipe(
switchMap(next => transform(next))
...
)
// RX.Net
observableOfObservables
.Switch()
.Select(next => transform(next))
...
在 RxJS 中,有一个 switchMap function. Is there an equivalent in ReactiveX/Rx.NET? I don't see one in the transforming 文档。
编辑
switch
是等价的。 http://reactivex.io/documentation/operators/switch.html
简而言之,switchMap
和 switch
将取消所有之前的流,而 flatMap
不会。
Rx.NET 中没有单个 SwitchMany 相当于 Rx.js 中的 switchMap。您需要使用单独的 Select 和 Switch 函数。
Observable.Interval(TimeSpan.FromMinutes(1))
.Select(_ => Observable.Return(10))
.Switch()
文档:https://msdn.microsoft.com/en-us/library/hh229197(v=vs.103).aspx
来自http://reactivex.io/documentation/operators/switch.html
Switch operator subscribes to an Observable that emits Observables. Each time it observes one of these emitted Observables, the Observable returned by Switch unsubscribes from the previously-emitted Observable begins emitting items from the latest Observable.
作为MorleyDev pointed, the .NET implementation is https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh229197(v=vs.103),所以 Rx.NET 中 RxJS switchMap 的等价物是 Switch 和 Select 运算符的组合:
// RxJS
observableOfObservables.pipe(
switchMap(next => transform(next))
...
)
// RX.Net
observableOfObservables
.Switch()
.Select(next => transform(next))
...