code: public static <T> Transformer<T, T> removePairs(
              final Func1<? super T, Boolean> isCandidateForFirst,
              final Func2<? super T, ? super T, Boolean> remove) {
          return new Transformer<T, T>() {
  
              @Override
              public Observable<T> call(Observable<T> o) {
                  return o.compose(Transformers. //
                  stateMachine() //
                          .initialState(Optional.<T> absent()) //
                          .transition(new Transition<Optional<T>, T, T>() {
  
                              @Override
                              public Optional<T> call(Optional<T> state, T value,
                                      Subscriber<T> subscriber) {
                                  if (!state.isPresent()) {
                                      if (isCandidateForFirst.call(value)) {
                                          return Optional.of(value);
                                      } else {
                                          subscriber.onNext(value);
                                          return Optional.absent();
                                      }
                                  } else {
                                      if (remove.call(state.get(), value)) {
                                          // emit nothing and reset state
                                          return Optional.absent();
                                      } else {
                                          subscriber.onNext(state.get());
                                          if (isCandidateForFirst.call(value)) {
                                              return Optional.of(value);
                                          } else {
                                              subscriber.onNext(value);
                                              return Optional.absent();
                                          }
                                      }
                                  }
                              }
                          }).completion(new Completion<Optional<T>, T>() {
  
                              @Override
                              public Boolean call(Optional<T> state, Subscriber<T> subscriber) {
                                  if (state.isPresent())
                                      subscriber.onNext(state.get());
                                  // yes, complete
                                  return true;
                              }
                          }).build());
              }
          };
      }
docs: Removes pairs non-recursively from a stream. Uses
  {@code Transformers.stateMachine()} under the covers to ensure items are
  emitted as soon as possible (if an item can't be in a pair then it is
  emitted straight away).
  
  @param isCandidateForFirst
  returns true if item is potentially the first of a pair that
  we want to remove
  @param remove
  returns true if a pair should be removed
  @param <T>
  generic type of stream being transformed
  @return transformed stream