Write generic code that works with any collection, or build your own collection types.
Sequence and Collection Protocols
Topics
First Steps
protocol SequenceA type that provides sequential, iterated access to its elements.
protocol CollectionA sequence whose elements can be traversed multiple times, nondestructively, and accessed by an indexed subscript.
Collection Traversal
protocol Bidirectional CollectionA collection that supports backward as well as forward traversal.
protocol Random Access CollectionA collection that supports efficient random-access index traversal.
Collection Mutability
protocol Mutable CollectionA collection that supports subscript assignment.
protocol Range Replaceable CollectionA collection that supports replacement of an arbitrary subrange of elements with the elements of another collection.
Manual Iteration
protocol Iterator ProtocolA type that supplies the values of a sequence one at a time.
Algebraic Sets
protocol Set AlgebraA type that provides mathematical set operations.
Lazy Collections
protocol Lazy Sequence ProtocolA sequence on which normally-eager operations such as map and filter are implemented lazily.
protocol Lazy Collection ProtocolA collection on which normally-eager operations such as map and filter are implemented lazily.
See Also
Advanced Collection Topics
Use wrappers, indices, and iterators in operations like slicing, flattening, and reversing a collection.
Build your own buffer-backed collection types.