Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the given predicate to compare elements.
SDK
- Xcode 11.0+
Framework
- Swift Standard Library
Declaration
func lexicographicallyPrecedes<OtherSequence>(_ other: OtherSequence, by areInIncreasingOrder: (CollectionDifference <ChangeElement>.Change, CollectionDifference <ChangeElement>.Change) throws -> Bool) rethrows -> Bool where OtherSequence : Sequence, Self.Element == OtherSequence.Element
Parameters
otherA sequence to compare to this sequence.
areInIncreasingOrderA predicate that returns
trueif its first argument should be ordered before its second argument; otherwise,false.
Return Value
true if this sequence precedes other in a dictionary ordering as ordered by are; otherwise, false.
Discussion
The predicate must be a strict weak ordering over the elements. That is, for any elements a, b, and c, the following conditions must hold:
Note
This method implements the mathematical notion of lexicographical ordering, which has no connection to Unicode. If you are sorting strings to present to the end user, use String APIs that perform localized comparison instead.
Complexity: O(m), where m is the lesser of the length of the sequence and the length of other.
areis alwaysIn Increasing Order(a, a) false. (Irreflexivity)If
areandIn Increasing Order(a, b) areare bothIn Increasing Order(b, c) true, thenareis alsoIn Increasing Order(a, c) true. (Transitive comparability)Two elements are incomparable if neither is ordered before the other according to the predicate. If
aandbare incomparable, andbandcare incomparable, thenaandcare also incomparable. (Transitive incomparability)