Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.
SDK
- Xcode 11.0+
Framework
- Swift Standard Library
Declaration
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 possible
; otherwise, false
. If possible
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 possible
always results in true
.
Complexity: O(m), where m is the lesser of the length of the sequence and the length of possible
.