---
title: "starts(with:by:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/prefixsequence/starts(with:by:)"
---

# 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.

## Declaration

```swift
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.

## Return Value

Return Value 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.

## Discussion

Discussion The predicate must be an equivalence relation over the elements. That is, for any elements a, b, and c, the following conditions must hold: areEquivalent(a, a) is always true. (Reflexivity) areEquivalent(a, b) implies areEquivalent(b, a). (Symmetry) If areEquivalent(a, b) and areEquivalent(b, c) are both true, then areEquivalent(a, c) is also true. (Transitivity) note: O(m), where m is the lesser of the length of the sequence and the length of possiblePrefix.
