From b219f3f75d6d117c9d4a775baf9cb24e1782494c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 22 Aug 2024 15:35:07 -0500 Subject: [PATCH] added == and != to existing Signed-off-by: Matt Bruce --- .../MVMCore/Models/Model/ModelProtocol.swift | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/MVMCore/MVMCore/Models/Model/ModelProtocol.swift b/MVMCore/MVMCore/Models/Model/ModelProtocol.swift index 8c85a64..3716199 100644 --- a/MVMCore/MVMCore/Models/Model/ModelProtocol.swift +++ b/MVMCore/MVMCore/Models/Model/ModelProtocol.swift @@ -109,3 +109,43 @@ public extension Optional { } } } + +func == (lhs: (any ModelComparisonProtocol)?, rhs: (any ModelComparisonProtocol)?) -> Bool { + switch (lhs, rhs) { + case (.some(let lhs), .some(let rhs)): + return lhs.isEqual(to: rhs) + case (.none, .none): + return true + default: + return false + } +} + +func != (lhs: (any ModelComparisonProtocol)?, rhs: (any ModelComparisonProtocol)?) -> Bool { + return !(lhs == rhs) +} + +func == (lhs: [any ModelComparisonProtocol]?, rhs: [any ModelComparisonProtocol]?) -> Bool { + switch (lhs, rhs) { + case (.some(let lhs), .some(let rhs)): + return lhs == rhs + case (.none, .none): + return true + default: + return false + } +} + +func != (lhs: [any ModelComparisonProtocol]?, rhs: [any ModelComparisonProtocol]?) -> Bool { + return !(lhs == rhs) +} + +func == (lhs: [any ModelComparisonProtocol], rhs: [any ModelComparisonProtocol]) -> Bool { + return lhs.elementsEqual(rhs, by: { (lhsElement, rhsElement) -> Bool in + return lhsElement == rhsElement + }) +} + +func != (lhs: [any ModelComparisonProtocol], rhs: [any ModelComparisonProtocol]) -> Bool { + return !(lhs == rhs) +}