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

# Collection Implementations

## Topics

### Instance Properties

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

Returns the number of elements.

[`var count: Int`](/documentation/Swift/LazySequence/count-1cggd)

The number of elements in the collection.

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

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

[`var indices: LazySequence<Base>.Indices`](/documentation/Swift/LazySequence/indices-swift.property)

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

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

A Boolean value indicating whether the collection is empty.

[`var isEmpty: Bool`](/documentation/Swift/LazySequence/isEmpty-1upms)

A Boolean value indicating whether the collection is empty.

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

The position of the first element in a non-empty collection.

### Instance Methods

[`func distance(from: LazySequence<Base>.Index, to: LazySequence<Base>.Index) -> Int`](/documentation/Swift/LazySequence/distance(from:to:))

Returns the distance between two indices.

[`func distance(from: Self.Index, to: Self.Index) -> Int`](/documentation/Swift/LazySequence/distance(from:to:)-396sb)

Returns the distance between two indices.

[`func firstIndex(of: Self.Element) -> Self.Index?`](/documentation/Swift/LazySequence/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/LazySequence/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/LazySequence/formIndex(_:offsetBy:))

Offsets the given index by the specified distance.

[`func formIndex(inout Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Bool`](/documentation/Swift/LazySequence/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/LazySequence/formIndex(after:))

Replaces the given index with its successor.

[`func index(LazySequence<Base>.Index, offsetBy: Int) -> LazySequence<Base>.Index`](/documentation/Swift/LazySequence/index(_:offsetBy:))

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

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

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

[`func index(LazySequence<Base>.Index, offsetBy: Int, limitedBy: LazySequence<Base>.Index) -> LazySequence<Base>.Index?`](/documentation/Swift/LazySequence/index(_:offsetBy:limitedBy:))

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

[`func index(Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Self.Index?`](/documentation/Swift/LazySequence/index(_:offsetBy:limitedBy:)-62vws)

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

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

Returns the position immediately after the given index.

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

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

[`func indices(of: Self.Element) -> RangeSet<Self.Index>`](/documentation/Swift/LazySequence/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/LazySequence/indices(where:))

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

[`func makeIterator() -> LazySequence<Base>.Iterator`](/documentation/Swift/LazySequence/makeIterator())

Returns an iterator over the elements of the collection.

[`func map<T, E>((Self.Element) throws(E) -> T) throws(E) -> [T]`](/documentation/Swift/LazySequence/map(_:)-7wx5z)

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/LazySequence/prefix(through:))

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

[`func prefix(upTo: Self.Index) -> Self.SubSequence`](/documentation/Swift/LazySequence/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/LazySequence/randomElement())

Returns a random element of the collection.

[`func randomElement<T>(using: inout T) -> Self.Element?`](/documentation/Swift/LazySequence/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/LazySequence/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/LazySequence/split(separator:maxSplits:omittingEmptySubsequences:)-ki1c)

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/LazySequence/suffix(from:))

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

### Subscripts

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

Accesses the element at `position`.

[`subscript(RangeSet<Self.Index>) -> DiscontiguousSlice<Self>`](/documentation/Swift/LazySequence/subscript(_:)-1iwxl)

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

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

[`subscript(Range<Self.Index>) -> Slice<Self>`](/documentation/Swift/LazySequence/subscript(_:)-8iflg)

Accesses a contiguous subrange of the collection’s elements.

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

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

### Type Aliases

[`typealias Index`](/documentation/Swift/LazySequence/Index)

A type that represents a valid position in the collection.

[`typealias Indices`](/documentation/Swift/LazySequence/Indices-swift.typealias)

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

[`typealias Iterator`](/documentation/Swift/LazySequence/Iterator)

A type that provides the collection’s iteration interface and
encapsulates its iteration state.

[`typealias SubSequence`](/documentation/Swift/LazySequence/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)