Avatar
@swift-4.2.4 @swift-5.0.3 enum Result<Value, Error> { case success(Value) case failure(Error) } extension Result: Equatable where Value: Equatable, Error: Equatable { static func == (lhs: Result, rhs: Result) -> Bool { switch (lhs, rhs) { case let (.success(lhs), .success(rhs)): return lhs == rhs case let (.failure(lhs), .failure(rhs)): return lhs == rhs case (.success, .failure), (.failure, .success): return false } } } extension Result: Hashable where Value: Hashable, Error: Hashable { var hashValue: Int { switch self { case let .success(value): return value.hashValue case let .failure(error): return error.hashValue } } } let foo = Result<Int, Never>.success(1) let bar = Result<Int, Never>.success(1) print(foo == bar) (edited)