Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 9, 2020 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdev/432803d9002fec10d46272aad29e430a to your computer and use it in GitHub Desktop.
Save jasdev/432803d9002fec10d46272aad29e430a to your computer and use it in GitHub Desktop.
`DataLoadState` sketch.
enum DataLoadState<Value, Error: Swift.Error> {
case initial
case loading
case loaded(Value)
case error(Error) /// (1) A challenging exercise for the reader is to think through extending
/// this type to support paginated loadings.
var isLoading: Bool { /// (2) Again, taking cue from Point Free’s enumeration properties work.
/// This will be helpful when enabling and disabling buttons while a request is in-flight.
switch self {
case .loading:
return true
default:
return false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment