<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/LazyPrefixWhileSequence/Collection-Implementations",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Collection Implementations"
}
-->

# Collection Implementations

## Topics

### Structures

[`struct Index`](/documentation/Swift/LazyPrefixWhileSequence/Index)

A position in a `LazyPrefixWhileCollection` or
`LazyPrefixWhileBidirectionalCollection` instance.

### Instance Properties

[`var count: Int`](/documentation/Swift/LazyPrefixWhileSequence/count)

The number of elements in the collection.

[`var endIndex: LazyPrefixWhileSequence<Base>.Index`](/documentation/Swift/LazyPrefixWhileSequence/endIndex)

The collection’s “past the end” position—that is, the position one
greater than the last valid subscript argument.

[`var indices: DefaultIndices<Self>`](/documentation/Swift/LazyPrefixWhileSequence/indices-swift.property)

The indices that are valid for subscripting the collection, in ascending
order.

[`var isEmpty: Bool`](/documentation/Swift/LazyPrefixWhileSequence/isEmpty)

A Boolean value indicating whether the collection is empty.

[`var startIndex: LazyPrefixWhileSequence<Base>.Index`](/documentation/Swift/LazyPrefixWhileSequence/startIndex)

The position of the first element in a nonempty collection.

### Instance Methods

[`func distance(from: Self.Index, to: Self.Index) -> Int`](/documentation/Swift/LazyPrefixWhileSequence/distance(from:to:)-5ytzv)

Returns the distance between two indices.

[`func firstIndex(of: Self.Element) -> Self.Index?`](/documentation/Swift/LazyPrefixWhileSequence/firstIndex(of:))

Returns the first index where the specified value appears in the
collection.

[`func firstIndex(where: (Self.Element) throws -> Bool) rethrows -> Self.Index?`](/documentation/Swift/LazyPrefixWhileSequence/firstIndex(where:))

Returns the first index in which an element of the collection satisfies
the given predicate.

[`func formIndex(inout Self.Index, offsetBy: Int)`](/documentation/Swift/LazyPrefixWhileSequence/formIndex(_:offsetBy:))

Offsets the given index by the specified distance.

[`func formIndex(inout Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Bool`](/documentation/Swift/LazyPrefixWhileSequence/formIndex(_:offsetBy:limitedBy:))

Offsets the given index by the specified distance, or so that it equals
the given limiting index.

[`func formIndex(after: inout Self.Index)`](/documentation/Swift/LazyPrefixWhileSequence/formIndex(after:))

Replaces the given index with its successor.

[`func index(Self.Index, offsetBy: Int) -> Self.Index`](/documentation/Swift/LazyPrefixWhileSequence/index(_:offsetBy:)-2y8r8)

Returns an index that is the specified distance from the given index.

[`func index(Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Self.Index?`](/documentation/Swift/LazyPrefixWhileSequence/index(_:offsetBy:limitedBy:)-279cj)

Returns an index that is the specified distance from the given index,
unless that distance is beyond a given limiting index.

[`func index(after: LazyPrefixWhileSequence<Base>.Index) -> LazyPrefixWhileSequence<Base>.Index`](/documentation/Swift/LazyPrefixWhileSequence/index(after:))

Returns the position immediately after the given index.

[`func index(of: Self.Element) -> Self.Index?`](/documentation/Swift/LazyPrefixWhileSequence/index(of:))

Returns the first index where the specified value appears in the
collection.

[`func indices(of: Self.Element) -> RangeSet<Self.Index>`](/documentation/Swift/LazyPrefixWhileSequence/indices(of:))

Returns the indices of all the elements that are equal to the given
element.

[`func indices(where: (Self.Element) throws -> Bool) rethrows -> RangeSet<Self.Index>`](/documentation/Swift/LazyPrefixWhileSequence/indices(where:))

Returns the indices of all the elements that match the given predicate.

[`func map<T, E>((Self.Element) throws(E) -> T) throws(E) -> [T]`](/documentation/Swift/LazyPrefixWhileSequence/map(_:)-69szl)

Returns an array containing the results of mapping the given closure
over the sequence’s elements.

[`func prefix(through: Self.Index) -> Self.SubSequence`](/documentation/Swift/LazyPrefixWhileSequence/prefix(through:))

Returns a subsequence from the start of the collection through the
specified position.

[`func prefix(upTo: Self.Index) -> Self.SubSequence`](/documentation/Swift/LazyPrefixWhileSequence/prefix(upTo:))

Returns a subsequence from the start of the collection up to, but not
including, the specified position.

[`func randomElement() -> Self.Element?`](/documentation/Swift/LazyPrefixWhileSequence/randomElement())

Returns a random element of the collection.

[`func randomElement<T>(using: inout T) -> Self.Element?`](/documentation/Swift/LazyPrefixWhileSequence/randomElement(using:))

Returns a random element of the collection, using the given generator as
a source for randomness.

[`func removingSubranges(RangeSet<Self.Index>) -> DiscontiguousSlice<Self>`](/documentation/Swift/LazyPrefixWhileSequence/removingSubranges(_:))

Returns a collection of the elements in this collection that are not
represented by the given range set.

[`func split(separator: Self.Element, maxSplits: Int, omittingEmptySubsequences: Bool) -> [Self.SubSequence]`](/documentation/Swift/LazyPrefixWhileSequence/split(separator:maxSplits:omittingEmptySubsequences:)-1na6p)

Returns the longest possible subsequences of the collection, in order,
around elements equal to the given element.

[`func suffix(from: Self.Index) -> Self.SubSequence`](/documentation/Swift/LazyPrefixWhileSequence/suffix(from:))

Returns a subsequence from the specified position to the end of the
collection.

### Subscripts

[`subscript(LazyPrefixWhileSequence<Base>.Index) -> LazyPrefixWhileSequence<Base>.Element`](/documentation/Swift/LazyPrefixWhileSequence/subscript(_:))

Accesses the element at the specified position.

[`subscript(UnboundedRange) -> Self.SubSequence`](/documentation/Swift/LazyPrefixWhileSequence/subscript(_:)-1oo1v)

[`subscript(Range<Self.Index>) -> Slice<Self>`](/documentation/Swift/LazyPrefixWhileSequence/subscript(_:)-59k49)

Accesses a contiguous subrange of the collection’s elements.

[`subscript(RangeSet<Self.Index>) -> DiscontiguousSlice<Self>`](/documentation/Swift/LazyPrefixWhileSequence/subscript(_:)-75yeo)

Accesses a view of this collection with the elements at the given
indices.

[`subscript<R>(R) -> Self.SubSequence`](/documentation/Swift/LazyPrefixWhileSequence/subscript(_:)-9tkrc)

Accesses the contiguous subrange of the collection’s elements specified
by a range expression.

### Type Aliases

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

A type that represents the indices that are valid for subscripting the
collection, in ascending order.

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

A collection representing a contiguous subrange of this collection’s
elements. The subsequence shares indices with the original collection.

---

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)