Skip to content

Instantly share code, notes, and snippets.

@shoheiyokoyama
Created August 3, 2017 01:04
Show Gist options
  • Save shoheiyokoyama/109c1697c1fb02c47557077904b9618a to your computer and use it in GitHub Desktop.
Save shoheiyokoyama/109c1697c1fb02c47557077904b9618a to your computer and use it in GitHub Desktop.
let killua = Player(level: Variable(50))
let gon = Player(level: Variable(50))
let bisque = Player(level: Variable(70))
let player = PublishSubject<Player>()
player.asObservable()
.flatMapWithIndex { player, index -> Observable<Int> in
if index < 2 {
return player.level.asObservable()
}
return .empty()
}
.subscribe(onNext: { print($0) })
.disposed(by: disposeBag)
player.onNext(killua) // 50
killua.level.value = 51 // 51
player.onNext(gon) //50
gon.level.value = 51 // 51
player.onNext(bisque) // level of bisque isn't printed.
killua.level.value = 52 // 52
gon.level.value = 52 // 52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment