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

Result class refactoring #1

Open
alexey-kravtsov-tc opened this issue Sep 16, 2019 · 1 comment
Open

Result class refactoring #1

alexey-kravtsov-tc opened this issue Sep 16, 2019 · 1 comment

Comments

@alexey-kravtsov-tc
Copy link

Great project, thanks for sharing!

I have some minor improve suggestion - Result class is currently implemented in Java style and not getting benefits of the Kotlin compiler.

Having Result class implemented as

sealed class Result<out T> {
    class loading<T> : Result<T>()
    data class error<T>(val message: String) : Result<T>()
    data class success<T>(val data: T) : Result<T>()
}

you can avoid excess nullability checks(!!) and possible exceptions in places like


            if (responseStatus.status == SUCCESS) {
                saveCallResult(responseStatus.data!!)
            } else if (responseStatus.status == ERROR) {
                emit(Result.error<T>(responseStatus.message!!))
                emitSource(source)
            }

and have it in more Kotlin way

            if (responseStatus is Result.success) {
                saveCallResult(responseStatus.data)
            } else if (responseStatus is Result.error) {
                emit(Result.error<T>(responseStatus.message))
                emitSource(source)
            }

Hope you find it useful :)

@Eli-Fox
Copy link
Owner

Eli-Fox commented Sep 23, 2019

That's great suggestion, @alexkrafts. I'll definitely take it as improvement.

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

2 participants