Generic Instance Method

starts(with:)

Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.

Parameters

`possiblePrefix`

A sequence to compare to this sequence.

Return Value

`true` if the initial elements of the sequence are the same as the elements of `possiblePrefix`; otherwise, `false`. If `possiblePrefix` has no elements, the return value is `true`.

Discussion

This example tests whether one countable range begins with the elements of another countable range.

Passing a sequence with no elements or an empty collection as `possiblePrefix` always results in `true`.

Complexity: O(m), where m is the lesser of the length of the sequence and the length of `possiblePrefix`.

See Also

Comparing Digests

`func elementsEqual<OtherSequence>(OtherSequence) -> Bool`

Returns a Boolean value indicating whether this sequence and another sequence contain the same elements in the same order.

`func elementsEqual<OtherSequence>(OtherSequence, by: (UInt8, OtherSequence.Element) -> Bool) -> Bool`

Returns a Boolean value indicating whether this sequence and another sequence contain equivalent elements in the same order, using the given predicate as the equivalence test.

`func starts<PossiblePrefix>(with: PossiblePrefix, by: (UInt8, PossiblePrefix.Element) -> Bool) -> Bool`

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 lexicographicallyPrecedes<OtherSequence>(OtherSequence) -> Bool`

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the less-than operator (`<`) to compare elements.

`func lexicographicallyPrecedes<OtherSequence>(OtherSequence, by: (UInt8, UInt8) -> Bool) -> Bool`

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the given predicate to compare elements.