<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/sequence-and-collection-protocols",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Sequence and Collection Protocols"
}
-->

# Sequence and Collection Protocols

Write generic code that works with any collection, or build your own collection types.

## Topics

### First Steps

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

A type that provides sequential, iterated access to its elements.

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

A sequence whose elements can be traversed multiple times,
nondestructively, and accessed by an indexed subscript.

### Collection Traversal

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

A collection that supports backward as well as forward traversal.

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

A collection that supports efficient random-access index traversal.

### Collection Mutability

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

A collection that supports subscript assignment.

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

A collection that supports replacement of an arbitrary subrange of elements
with the elements of another collection.

### Manual Iteration

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

A type that supplies the values of a sequence one at a time.

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

A type that provides borrowed access to the values of a borrowing sequence.

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

### Algebraic Sets

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

A type that provides mathematical set operations.

### Lazy Collections

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

A sequence on which normally-eager sequence operations are implemented
lazily.

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



---

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)