Q:

Observable If else in RxSwift

I made Observable of Bool type as below
let allValid: Observable<Bool>

//All valid is combination of two more Observable<Bool>
allValid = Observable.combineLatest(checkBoxValid, reasonValid) { $0 && $1 }

Now I want to check when Done button is pressed, call respective method based on value of AllValid.
public func doneButtonPressed() {
//Here I have two methods, and to be called, when AllValid is true and false

//self.method1()
//self.method2()
}

Now how to make it. I cannot bind directly as it will trigger, and I want to trigger when Done is pressed. 

A:

The Rx way to do this would be to put this in your viewDidLoad
let isValid = doneButton.rx.tap.withLatestFrom(allValid)

isValid
    .filter { $0 }
    .subscribe(onNext: { _ in 
        // The button was tapped while the last value from allValid was true.
    }
    .disposed(by: bag)

isValid
    .filter { !$0 }
    .subscribe(onNext: { _ in 
        // The button was tapped while the last value from allValid was false.
    }
    .disposed(by: bag)

