Rx: combineLatest vs withLatestFrom (and zip)

Martin Konicek
Jan 17, 2018 · 3 min read


disposables += Observable.combineLatest(        view.onNameChanged(), view.onEmailChanged(), ::AccountInfo)        .subscribe { accountInfo ->               view.setNextStepButtonEnabled(accountInfo.isValid())        }


disposables += view.onNameFocusChanged()      // When focus changes          .withLatestFrom(view.onNameChanged()) // Grab the name          .subscribe { (focus, name) ->            val hasLostFocus = !focus            if (hasLostFocus && !isValidName(name)) {              view.showInvalidName()            } else {              view.clearNameError()            }          }

What about the zip operator?

When each Observable returns at most one value: zip and combineLatest will do the same thing.

Martin Konicek

Written by

Software Engineer based in London

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade