// // AnyEquatable.swift // VDS // // Created by Matt Bruce on 9/15/22. // import Foundation public protocol AnyEquatable { func isEqual(_ equatable: AnyEquatable) -> Bool } func == (lhs: AnyEquatable?, rhs: AnyEquatable?) -> Bool { switch (lhs, rhs) { case (.some(let lhs), .some(let rhs)): return lhs.isEqual(rhs) case (.none, .none): return true default: return false } } func != (lhs: AnyEquatable?, rhs: AnyEquatable?) -> Bool { return !(lhs == rhs) } func == (lhs: [AnyEquatable]?, rhs: [AnyEquatable]?) -> Bool { switch (lhs, rhs) { case (.some(let lhs), .some(let rhs)): return lhs == rhs case (.none, .none): return true default: return false } } func != (lhs: [AnyEquatable]?, rhs: [AnyEquatable]?) -> Bool { return !(lhs == rhs) } func == (lhs: [AnyEquatable], rhs: [AnyEquatable]) -> Bool { return lhs.elementsEqual(rhs, by: { (lhsElement, rhsElement) -> Bool in return lhsElement == rhsElement }) } func != (lhs: [AnyEquatable], rhs: [AnyEquatable]) -> Bool { return !(lhs == rhs) }