@@ -0,0 +1,2019 @@
+/*%0A * Copyright 2019 Google LLC%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     https://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.google.android.gnd.rx;%0A%0Aimport androidx.annotation.NonNull;%0Aimport io.reactivex.Single;%0Aimport io.reactivex.functions.Consumer;%0Aimport javax.annotation.Nullable;%0A%0Apublic class Result%3CT%3E %7B%0A  public enum State %7B%0A    SUCCESS,%0A    ERROR%0A  %7D%0A%0A  private final State state;%0A%0A  @Nullable private final T value;%0A  @Nullable private final Throwable error;%0A%0A  private Result(State state, @Nullable T value, @Nullable Throwable error) %7B%0A    this.state = state;%0A    this.value = value;%0A    this.error = error;%0A  %7D%0A%0A  public static %3CT%3E Result%3CT%3E success(@NonNull T result) %7B%0A    return new Result%3C%3E(State.SUCCESS, result, null);%0A  %7D%0A%0A  public static %3CT%3E Result%3CT%3E error(@NonNull Throwable t) %7B%0A    return new Result%3C%3E(State.ERROR, null, t);%0A  %7D%0A%0A  @Nullable%0A  public State getState() %7B%0A    return state;%0A  %7D%0A%0A  @Nullable%0A  public T get() %7B%0A    return value;%0A  %7D%0A%0A  @Nullable%0A  public Throwable getError() %7B%0A    return error;%0A  %7D%0A%0A  public static %3CT%3E Single%3CResult%3CT%3E%3E wrap(Single%3CT%3E single) %7B%0A    return single.map(Result::success).onErrorReturn(Result::error);%0A  %7D%0A%0A  public static %3CT%3E Consumer%3C? super Result%3CT%3E%3E unwrap(%0A      Consumer%3CT%3E onSuccess, Consumer%3CThrowable%3E onError) %7B%0A    return result -%3E %7B%0A      switch (result.getState()) %7B%0A        case SUCCESS:%0A          onSuccess.accept(result.get());%0A          break;%0A        case ERROR:%0A          onError.accept(result.getError());%0A          break;%0A      %7D%0A    %7D;%0A  %7D%0A%7D%0A

Add simple wrapper for streaming results