Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let disposeBag = DisposeBag()
let persons = PublishSubject<Person>()
persons
.flatMapLatest {
$0.car
}
.subscribe(onNext: {
print($0)
})
.disposed(by: disposeBag)
let john = Person(car: BehaviorSubject(value: "Toyota Corolla"))
persons.onNext(john)
let alice = Person(car: BehaviorSubject(value: "Honda Accord"))
persons.onNext(alice)
john.car.onNext("Ford Model T")
// Output:
// Toyota Corolla
// Honda Accord
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment