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

# Sequence Implementations

## Topics

### Structures

[`struct Iterator`](/documentation/Swift/UnsafeRawBufferPointer/Iterator)

An iterator over the bytes viewed by a raw buffer pointer.

### Instance Properties

[`var lazy: LazySequence<Self>`](/documentation/Swift/UnsafeRawBufferPointer/lazy)

A sequence containing the same elements as this sequence,
but on which some operations, such as `map` and `filter`, are
implemented lazily.

### Instance Methods

[`func allSatisfy((Self.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/UnsafeRawBufferPointer/allSatisfy(_:))

Returns a Boolean value indicating whether every element of a sequence
satisfies a given predicate.

[`func compactMap<ElementOfResult>((Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult]`](/documentation/Swift/UnsafeRawBufferPointer/compactMap(_:))

Returns an array containing the non-`nil` results of calling the given
transformation with each element of this sequence.

[`func contains(Self.Element) -> Bool`](/documentation/Swift/UnsafeRawBufferPointer/contains(_:))

Returns a Boolean value indicating whether the sequence contains the
given element.

[`func contains(where: (Self.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/UnsafeRawBufferPointer/contains(where:))

Returns a Boolean value indicating whether the sequence contains an
element that satisfies the given predicate.

[`func count<E>(where: (Self.Element) throws(E) -> Bool) throws(E) -> Int`](/documentation/Swift/UnsafeRawBufferPointer/count(where:))

Returns the number of elements in the sequence that satisfy the given
predicate.

[`func elementsEqual<OtherSequence>(OtherSequence) -> Bool`](/documentation/Swift/UnsafeRawBufferPointer/elementsEqual(_:))

Returns a Boolean value indicating whether this sequence and another
sequence contain the same elements in the same order.

[`func elementsEqual<OtherSequence>(OtherSequence, by: (Self.Element, OtherSequence.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/UnsafeRawBufferPointer/elementsEqual(_:by:))

Returns a Boolean value indicating whether this sequence and another
sequence contain equivalent elements in the same order, using the given
predicate as the equivalence test.

[`func enumerated() -> EnumeratedSequence<Self>`](/documentation/Swift/UnsafeRawBufferPointer/enumerated())

Returns a sequence of pairs (*n*, *x*), where *n* represents a
consecutive integer starting at zero and *x* represents an element of
the sequence.

[`func filter<E>((Self.Element) throws(E) -> Bool) throws(E) -> [Self.Element]`](/documentation/Swift/UnsafeRawBufferPointer/filter(_:))

Returns an array containing, in order, the elements of the sequence
that satisfy the given predicate.

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

Returns the first element of the sequence that satisfies the given
predicate.

[`func flatMap<ElementOfResult>((Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult]`](/documentation/Swift/UnsafeRawBufferPointer/flatMap(_:)-6chuu)

[`func flatMap<SegmentOfResult>((Self.Element) throws -> SegmentOfResult) rethrows -> [SegmentOfResult.Element]`](/documentation/Swift/UnsafeRawBufferPointer/flatMap(_:)-i3md)

Returns an array containing the concatenated results of calling the
given transformation with each element of this sequence.

[`func forEach((Self.Element) throws -> Void) rethrows`](/documentation/Swift/UnsafeRawBufferPointer/forEach(_:))

Calls the given closure on each element in the sequence in the same order
as a `for`-`in` loop.

[`func lexicographicallyPrecedes<OtherSequence>(OtherSequence) -> Bool`](/documentation/Swift/UnsafeRawBufferPointer/lexicographicallyPrecedes(_:))

Returns a Boolean value indicating whether the sequence precedes another
sequence in a lexicographical (dictionary) ordering, using the
less-than operator (`<`) to compare elements.

[`func lexicographicallyPrecedes<OtherSequence>(OtherSequence, by: (Self.Element, Self.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/UnsafeRawBufferPointer/lexicographicallyPrecedes(_:by:))

Returns a Boolean value indicating whether the sequence precedes another
sequence in a lexicographical (dictionary) ordering, using the given
predicate to compare elements.

[`func makeIterator() -> UnsafeRawBufferPointer.Iterator`](/documentation/Swift/UnsafeRawBufferPointer/makeIterator())

Returns an iterator over the bytes of this sequence.

[`func map<T, E>((Self.Element) throws(E) -> T) throws(E) -> [T]`](/documentation/Swift/UnsafeRawBufferPointer/map(_:)-9jnnz)

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

[`func max() -> Self.Element?`](/documentation/Swift/UnsafeRawBufferPointer/max())

Returns the maximum element in the sequence.

[`func max(by: (Self.Element, Self.Element) throws -> Bool) rethrows -> Self.Element?`](/documentation/Swift/UnsafeRawBufferPointer/max(by:))

Returns the maximum element in the sequence, using the given predicate
as the comparison between elements.

[`func min() -> Self.Element?`](/documentation/Swift/UnsafeRawBufferPointer/min())

Returns the minimum element in the sequence.

[`func min(by: (Self.Element, Self.Element) throws -> Bool) rethrows -> Self.Element?`](/documentation/Swift/UnsafeRawBufferPointer/min(by:))

Returns the minimum element in the sequence, using the given predicate as
the comparison between elements.

[`func reduce<Result>(Result, (Result, Self.Element) throws -> Result) rethrows -> Result`](/documentation/Swift/UnsafeRawBufferPointer/reduce(_:_:))

Returns the result of combining the elements of the sequence using the
given closure.

[`func reduce<Result>(into: Result, (inout Result, Self.Element) throws -> ()) rethrows -> Result`](/documentation/Swift/UnsafeRawBufferPointer/reduce(into:_:))

Returns the result of combining the elements of the sequence using the
given closure.

[`func shuffled() -> [Self.Element]`](/documentation/Swift/UnsafeRawBufferPointer/shuffled())

Returns the elements of the sequence, shuffled.

[`func shuffled<T>(using: inout T) -> [Self.Element]`](/documentation/Swift/UnsafeRawBufferPointer/shuffled(using:))

Returns the elements of the sequence, shuffled using the given generator
as a source for randomness.

[`func sorted() -> [Self.Element]`](/documentation/Swift/UnsafeRawBufferPointer/sorted())

Returns the elements of the sequence, sorted.

[`func sorted(by: (Self.Element, Self.Element) throws -> Bool) rethrows -> [Self.Element]`](/documentation/Swift/UnsafeRawBufferPointer/sorted(by:))

Returns the elements of the sequence, sorted using the given predicate as
the comparison between elements.

[`func starts<PossiblePrefix>(with: PossiblePrefix) -> Bool`](/documentation/Swift/UnsafeRawBufferPointer/starts(with:))

Returns a Boolean value indicating whether the initial elements of the
sequence are the same as the elements in another sequence.

[`func starts<PossiblePrefix>(with: PossiblePrefix, by: (Self.Element, PossiblePrefix.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/UnsafeRawBufferPointer/starts(with:by:))

Returns a Boolean value indicating whether the initial elements of the
sequence are equivalent to the elements in another sequence, using
the given predicate as the equivalence test.

[`func withContiguousStorageIfAvailable<R>((UnsafeBufferPointer<UnsafeRawBufferPointer.Element>) throws -> R) rethrows -> R?`](/documentation/Swift/UnsafeRawBufferPointer/withContiguousStorageIfAvailable(_:))

Executes a closure on the sequence’s contiguous storage.

[`func withContiguousStorageIfAvailable<R>((UnsafeBufferPointer<Self.Element>) throws -> R) rethrows -> R?`](/documentation/Swift/UnsafeRawBufferPointer/withContiguousStorageIfAvailable(_:)-1ynru)

Executes a closure on the sequence’s contiguous storage.

### Type Aliases

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

A type representing the sequence’s elements.

---

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)