Returns a Boolean value indicating whether the initial elements of the sequence are equivalent to the elements in another sequence, using the given predicate as the equivalence test.
SDK
- Xcode 10.0+
Framework
- Swift Standard Library
Declaration
Parameters
possiblePrefixA sequence to compare to this sequence.
areEquivalentA predicate that returns
trueif its two arguments are equivalent; otherwise,false.
Return Value
true if the initial elements of the sequence are equivalent to the elements of possible; otherwise, false. If possible has no elements, the return value is true.
Discussion
The predicate must be a equivalence relation over the elements. That is, for any elements a, b, and c, the following conditions must hold:
Complexity: O(m), where m is the lesser of the length of the sequence and the length of possible.
areis alwaysEquivalent(a, a) true. (Reflexivity)areimpliesEquivalent(a, b) are. (Symmetry)Equivalent(b, a) If
areandEquivalent(a, b) areare bothEquivalent(b, c) true, thenareis alsoEquivalent(a, c) true. (Transitivity)