lexicographicallyPrecedes(_:by:)
Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the given predicate to compare elements.
func lexicographicallyPrecedes<OtherSequence>(_ other: OtherSequence, by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool) rethrows -> Bool where OtherSequence : Sequence, Self.Element == OtherSequence.Element
Parameters
- other
A sequence to compare to this sequence.
- areInIncreasingOrder
A predicate that returns
true
if its first argument should be ordered before its second argument; otherwise,false
.
Returns
true
if this sequence precedes other
in a dictionary ordering as ordered by areInIncreasingOrder
; otherwise, false
.
Overview
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:
areInIncreasingOrder(a, a)
is alwaysfalse
. (Irreflexivity)If
areInIncreasingOrder(a, b)
andareInIncreasingOrder(b, c)
are bothtrue
, thenareInIncreasingOrder(a, c)
is alsotrue
. (Transitive comparability)Two elements are incomparable if neither is ordered before the other according to the predicate. If
a
andb
are incomparable, andb
andc
are incomparable, thena
andc
are also incomparable. (Transitive incomparability)