Skip to content

Instantly share code, notes, and snippets.

@marcinOz
Last active June 14, 2018 13:19
Show Gist options
  • Save marcinOz/0920e414d3da5e4e31cd95ad2a9779a1 to your computer and use it in GitHub Desktop.
Save marcinOz/0920e414d3da5e4e31cd95ad2a9779a1 to your computer and use it in GitHub Desktop.
sealed class ResourceState<T>
class LoadingState<T> : ResourceState<T>() {
override fun hashCode(): Int = javaClass.hashCode()
override fun equals(other: Any?) = equalz(other)
}
class EmptyState<T> : ResourceState<T>() {
override fun hashCode(): Int = javaClass.hashCode()
override fun equals(other: Any?) = equalz(other)
}
data class PopulatedState<T>(val data: T) : ResourceState<T>()
data class ErrorState<T>(val message: String?) : ResourceState<T>()
inline fun <reified T : ResourceState<*>> T.equalz(other: Any?) = when {
this === other -> true
other !is T -> false
else -> true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment