diff --git a/Sources/LoadingSignal.swift b/Sources/LoadingSignal.swift index 1eab428..9f824b8 100644 --- a/Sources/LoadingSignal.swift +++ b/Sources/LoadingSignal.swift @@ -80,6 +80,26 @@ public enum LoadingState: LoadingStateProtoco } } +extension LoadingState: Equatable where LoadingValue: Equatable, LoadingError: Equatable { + public static func == ( + lhs: LoadingState, + rhs: LoadingState) -> 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 {