starts(with:by:)
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.
func starts<PossiblePrefix>(with possiblePrefix: PossiblePrefix, by areEquivalent: (Self.Element, PossiblePrefix.Element) throws -> Bool) rethrows -> Bool where PossiblePrefix : Sequence
Parameters
- possiblePrefix
A sequence to compare to this sequence.
- areEquivalent
A predicate that returns
true
if its two arguments are equivalent; otherwise,false
.
Returns
true
if the initial elements of the sequence are equivalent to the elements of possiblePrefix
; otherwise, false
. If possiblePrefix
has no elements, the return value is true
.
Overview
The predicate must be a equivalence relation over the elements. That is, for any elements a
, b
, and c
, the following conditions must hold:
areEquivalent(a, a)
is alwaystrue
. (Reflexivity)areEquivalent(a, b)
impliesareEquivalent(b, a)
. (Symmetry)If
areEquivalent(a, b)
andareEquivalent(b, c)
are bothtrue
, thenareEquivalent(a, c)
is alsotrue
. (Transitivity)