Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Result type for returning success result or error #59

Open
FZambia opened this issue Feb 14, 2023 · 0 comments
Open

Use Result type for returning success result or error #59

FZambia opened this issue Feb 14, 2023 · 0 comments

Comments

@FZambia
Copy link
Member

FZambia commented Feb 14, 2023

Where we currently use void onDone​(@Nullable java.lang.Throwable e, @Nullable T result).

Similar to Result type we use in our Swift SDK. Or similar to kotlin.Result.

In Java it may be sth like this:

public class Result<T> {
    private T result;
    private Throwable error;

    private Result(T result, Throwable error) {
        this.result = result;
        this.error = error;
    }

    public static <T> Result<T> success(T result) {
        return new Result<>(result, null);
    }

    public static <T> Result<T> error(Throwable error) {
        return new Result<>(null, error);
    }

    public T getResult() {
        return result;
    }

    public Throwable getError() {
        return error;
    }

    public boolean isSuccess() {
        return error == null;
    }

    public boolean isError() {
        return error != null;
    }
}

For now opened to collect opinions, unfortunately this will break API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant