Open
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
Author
|
@Alex009 I did |
|
Kudos, SonarCloud Quality Gate passed! |
Alex009
reviewed
Jul 12, 2021
Comment on lines
+8
to
+11
| 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>() |
Member
There was a problem hiding this comment.
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()
}
Alex009
requested changes
Jul 13, 2021
|
|
||
| fun <T, E> List<T>.asState(): ResourceState<List<T>, E> = if (this.isEmpty()) { | ||
| ResourceState.Empty() | ||
| ResourceState.Empty |
Member
There was a problem hiding this comment.
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> { |
Member
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generics now are more meaningful, and redundant generics were removed