Returns the minimum element in the sequence, using the given predicate as the comparison between elements.
- Xcode 9.0+
- Swift Standard Library
A predicate that returns
trueif its first argument should be ordered before its second argument; otherwise,
The sequence’s minimum element, according to
are. If the sequence has no elements, returns
The predicate must be a strict weak ordering over the elements. That is, for any elements
c, the following conditions must hold:
In Increasing Order(a, a)
In Increasing Order(a, b)
In Increasing Order(b, c)
In Increasing Order(a, c)
true. (Transitive comparability)
Two elements are incomparable if neither is ordered before the other according to the predicate. If
bare incomparable, and
care incomparable, then
care also incomparable. (Transitive incomparability)
This example shows how to use the
min(by:) method on a dictionary to find the key-value pair with the lowest value.
Complexity: O(n), where n is the length of the sequence.