diff --git a/Sources/mas/Utilities/Collection.swift b/Sources/mas/Utilities/Collection.swift index ee686d35..87e0ad94 100644 --- a/Sources/mas/Utilities/Collection.swift +++ b/Sources/mas/Utilities/Collection.swift @@ -5,6 +5,12 @@ // Copyright © 2025 mas-cli. All rights reserved. // +extension Collection { + func dropLast(while predicate: (Element) throws -> Bool) rethrows -> SubSequence { + try indices.reversed().first { try !predicate(self[$0]) }.map { self[...$0] } ?? self[endIndex...] + } +} + extension Collection { func compactMap(_ transform: (Element) async throws(E) -> T?) async throws(E) -> [T] { var transformedElements = [T]() diff --git a/Sources/mas/Utilities/Version+SemVer.swift b/Sources/mas/Utilities/Version+SemVer.swift index 6f181554..f2f52cbb 100644 --- a/Sources/mas/Utilities/Version+SemVer.swift +++ b/Sources/mas/Utilities/Version+SemVer.swift @@ -186,7 +186,8 @@ private extension String { private extension [String] { func compareSemVerElements(to that: Self) -> ComparisonResult { - zip(self, that).first { $0 != $1 }.map { $0.compareSemVerElement(to: $1) } ?? (count.compare(to: that.count)) + zip(self, that).first { $0 != $1 }.map { $0.compareSemVerElement(to: $1) } + ?? dropLast { $0 == "0" }.count.compare(to: that.dropLast { $0 == "0" }.count) // swiftformat:disable:this indent } }