-
Notifications
You must be signed in to change notification settings - Fork 95
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
Work on generics in ResourceState #152
base: develop
Are you sure you want to change the base?
Conversation
Now the generics name in the ResourceState class is `TValue`, `TError` instead of `T`, `E`. It is important to have understandable generics names while `T` and `E` may be misinterpreted (e.g. `T` as Throwable). Generic names is kinda stuff that safe to refactor.
Since in Kotlin Type System every Type extends Nothing, and ResourceState generics are covariant, it is possible to remove redundant generics and replace them with Nothing. All usages in library updated
@Alex009 I did |
Kudos, SonarCloud Quality Gate passed! |
data class Success<out TData>(val data: TData) : ResourceState<TData, Nothing>() | ||
data class Failed<out TError>(val error: TError) : ResourceState<Nothing, TError>() | ||
object Loading : ResourceState<Nothing, Nothing>() | ||
object Empty : ResourceState<Nothing, Nothing>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in common:
class Test {
val myData: ResourceState<Int, String> = ResourceState.Success(10)
}
try on swift:
func test() {
let test = Test()
let data = test.myData as? ResourceStateSuccess<Int>
let data2: ResourceStateSuccess<Int> = test.myData.asSuccess()
}
@@ -11,7 +11,7 @@ fun <T, E> T?.asState(whenNull: () -> ResourceState<T, E>): ResourceState<T, E> | |||
this?.asState() ?: whenNull() | |||
|
|||
fun <T, E> List<T>.asState(): ResourceState<List<T>, E> = if (this.isEmpty()) { | |||
ResourceState.Empty() | |||
ResourceState.Empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also add into release notes guide to migration. please add migration regexp to pr description, we will add it into release notes later
data class Failed<out T, out E>(val error: E) : ResourceState<T, E>() | ||
class Loading<out T, out E> : ResourceState<T, E>() | ||
class Empty<out T, out E> : ResourceState<T, E>() | ||
sealed class ResourceState<out TData, out TError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change should support simple automatically migration if we want to merge it...try to write some regexp which will allow us and others migrate to new version in minutes on any size of project codebase
Generics now are more meaningful, and redundant generics were removed