import RxSwift
import PlaygroundSupport
import Foundation
PlaygroundPage.current.needsIndefiniteExecution = true

let disposeBag = DisposeBag()

// Flat Map Example – Game Price

struct Game {
    var price: Variable<Double>
}

let overwatch = Game(price: Variable(59.99))
let starwhal = Game(price: Variable(19.99))

let gameSubject = PublishSubject<Game>()

gameSubject
    .flatMap {
        $0.price.asObservable()
    }.subscribe(onNext: {
        print("Game Price: $\($0)")
    })
    .addDisposableTo(disposeBag)

gameSubject.onNext(overwatch)
gameSubject.onNext(starwhal)
