vds_ios/VDS/Protocols/AnyEquatable.swift
Matt Bruce b4659a73c0 added equatble to label
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-09-15 16:45:56 -05:00

53 lines
1.1 KiB
Swift

//
// 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)
}