| Crates.io | rx_core_operator_concat_map |
| lib.rs | rx_core_operator_concat_map |
| version | 0.2.0 |
| created_at | 2026-01-19 13:06:37.794975+00 |
| updated_at | 2026-01-24 15:05:15.520616+00 |
| description | concat_map operator for rx_core |
| homepage | https://github.com/AlexAegis/rx_bevy |
| repository | https://github.com/AlexAegis/rx_bevy |
| max_upload_size | |
| id | 2054593 |
| size | 17,350 |
Map each value to an inner observable and subscribe to them one at a time in order.
cargo run -p rx_core --example operator_concat_map_example
#[derive(Clone, Debug)]
enum Either {
Left,
Right,
}
let mut upstream_subject = PublishSubject::<Either>::default();
let mut inner_left_subject = PublishSubject::<i32>::default();
let mut inner_right_subject = PublishSubject::<i32>::default();
let l = inner_left_subject.clone();
let r = inner_right_subject.clone();
let mut _subscription = upstream_subject
.clone()
.finalize(|| println!("finalize: upstream"))
.tap_next(|n| println!("emit (source): {n:?}"))
.concat_map(
move |next| match next {
Either::Left => l.clone(),
Either::Right => r.clone(),
},
Never::map_into(),
)
.finalize(|| println!("finalize: downstream"))
.subscribe(PrintObserver::new("concat_map"));
upstream_subject.next(Either::Left);
inner_left_subject.next(1);
inner_right_subject.next(2);
inner_left_subject.next(3);
inner_right_subject.next(4);
upstream_subject.next(Either::Right);
inner_left_subject.next(5);
inner_right_subject.next(6);
inner_left_subject.next(7);
inner_right_subject.next(8);
inner_left_subject.complete();
inner_left_subject.next(9);
inner_right_subject.next(10);
inner_right_subject.complete();
upstream_subject.complete();
Output:
emit (source): Left
concat_map - next: 1
concat_map - next: 3
emit (source): Right
concat_map - next: 5
concat_map - next: 7
concat_map - next: 10
concat_map - completed
finalize: downstream
finalize: upstream
concat_map - unsubscribed