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

Add Equatable conformance to LoadingState #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Sources/LoadingSignal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ public enum LoadingState<LoadingValue, LoadingError: Error>: LoadingStateProtoco
}
}

extension LoadingState: Equatable where LoadingValue: Equatable, LoadingError: Equatable {
public static func == (
lhs: LoadingState<LoadingValue, LoadingError>,
rhs: LoadingState<LoadingValue, LoadingError>) -> Bool {
switch (lhs, rhs) {
case let (.loaded(lhsValue), .loaded(rhsValue)):
return lhsValue == rhsValue

case let (.failed(lhsError), .failed(rhsError)):
return lhsError == rhsError

case (.loading, .loading):
return true

default:
return false
}
}
}

/// Loading state as observed by the observer. Just like LoadingState, but with `.reloading` case.
/// To get observed loading state from a loading signal, apply `deriveObservedLoadingState()` operator.
public protocol ObservedLoadingStateProtocol: LoadingStateProtocol {
Expand Down