<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/LazyPrefixWhileSequence",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s23LazyPrefixWhileSequenceV"
  },
  "title" : "LazyPrefixWhileSequence"
}
-->

# LazyPrefixWhileSequence

A sequence whose elements consist of the initial consecutive elements of
some base sequence that satisfy a given predicate.

```
@frozen struct LazyPrefixWhileSequence<Base> where Base : Sequence
```

## Overview> Note: When `LazyPrefixWhileSequence` wraps a collection type, the
> performance of accessing `endIndex` depends on how many
> elements satisfy the predicate at the start of the collection, and might
> not offer the usual performance given by the `Collection` protocol.
> Accessing `endIndex`, the `last` property, or calling methods that
> depend on moving indices might not have the documented complexity.

## Topics

### Type Aliases

[`typealias Element`](/documentation/Swift/LazyPrefixWhileSequence/Element)

A type representing the sequence’s elements.

### Default Implementations

[BidirectionalCollection Implementations](/documentation/Swift/LazyPrefixWhileSequence/BidirectionalCollection-Implementations)

[Collection Implementations](/documentation/Swift/LazyPrefixWhileSequence/Collection-Implementations)

[LazySequenceProtocol Implementations](/documentation/Swift/LazyPrefixWhileSequence/LazySequenceProtocol-Implementations)

[Sequence Implementations](/documentation/Swift/LazyPrefixWhileSequence/Sequence-Implementations)

## Relationships

### Conforms To

[`LazySequenceProtocol`](/documentation/Swift/LazySequenceProtocol)

[`Copyable`](/documentation/Swift/Copyable)

[`Escapable`](/documentation/Swift/Escapable)

[`Collection`](/documentation/Swift/Collection)

[`LazyCollectionProtocol`](/documentation/Swift/LazyCollectionProtocol)

[`Sequence`](/documentation/Swift/Sequence)

[`BidirectionalCollection`](/documentation/Swift/BidirectionalCollection)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)