SwitchMap Operator
Rocket.switch_map — Functionswitch_map(::Type{R}, mappingFn::F = identity) where { R, F <: Function }Creates a switch_map operator, which returns an Observable that emits items based on applying a function mappingFn that you supply to each item emitted by the source Observable, where that function returns an (so-called "inner") Observable. Each time it observes one of these inner Observables, the output Observable begins emitting the items emitted by that inner Observable. When a new inner Observable is emitted, switch_map stops emitting items from the earlier-emitted inner Observable and begins emitting items from the new one. It continues to behave like this for subsequent inner Observables.
Arguments
::Type{R}: the type of data of output Observables after projection withmappingFnmappingFn::F: projection function with(data) -> Observable{R}signature
Producing
Stream of type <: Subscribable{R}
Examples
using Rocket
source = from([ of(1), of(2), of(3) ])
subscribe!(source |> switch_map(Int), logger())
;
# output
[LogActor] Data: 1
[LogActor] Data: 2
[LogActor] Data: 3
[LogActor] Completedusing Rocket
source = from([ 1, 2, 3 ])
subscribe!(source |> switch_map(Float64, (d) -> of(convert(Float64, d ^ 2))), logger())
;
# output
[LogActor] Data: 1.0
[LogActor] Data: 4.0
[LogActor] Data: 9.0
[LogActor] CompletedSee also: AbstractOperator, RightTypedOperator, ProxyObservable, logger