rx计算器源码

Observable.from(commands) .merge() .scan(CalculatorState.CLEAR_STATE) { a, x in return a.tranformState(x) } .debug("debugging") .subscribe(onNext: { [weak self] calState in self?.resultLabel.text = calState.inScreen switch calState.action { case .operation(let operation): switch operation { case .addition: self?.lastSignLabel.text = "+" case .subtraction: self?.lastSignLabel.text = "-" case .multiplication: self?.lastSignLabel.text = "x" case .division: self?.lastSignLabel.text = "/" } default: self?.lastSignLabel.text = "" } }) .addDisposableTo(disposeBag)

    推荐阅读