Instance Methodswift 6.0.1Swift
starts(with:)
Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.
func starts<PossiblePrefix>(with possiblePrefix: PossiblePrefix) -> Bool where PossiblePrefix : Sequence, Self.Element == PossiblePrefix.Element
Parameters
- possiblePrefix
A sequence to compare to this sequence.
Returns
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
.
This example tests whether one countable range begins with the elements of another countable range.
let a = 1...3
let b = 1...10
print(b.starts(with: a))
// Prints "true"
Passing a sequence with no elements or an empty collection as possiblePrefix
always results in true
.
print(b.starts(with: []))
// Prints "true"
Other members in extension
Instance members
func contains(Self.Element
) -> Bool Returns a Boolean value indicating whether the sequence contains the given element.
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 split(separator: Self.Element, maxSplits: Int, omittingEmptySubsequences: Bool
) -> [ArraySlice<Self.Element>] Returns the longest possible subsequences of the sequence, in order, around elements equal to the given element.