Instance Method


Returns a sequence, up to the specified maximum length, containing the initial elements of the sequence.


func prefix(_ maxLength: Int) -> PrefixSequence<SHA256Digest>



The maximum number of elements to return. The value of maxLength must be greater than or equal to zero.

Return Value

A sequence starting at the beginning of this sequence with at most maxLength elements.


If the maximum length exceeds the number of elements in the sequence, the result contains all the elements in the sequence.

let numbers = [1, 2, 3, 4, 5]
// Prints "[1, 2]"
// Prints "[1, 2, 3, 4, 5]"

Complexity: O(1)

See Also

Selecting Bytes

func filter((UInt8) -> Bool) -> [UInt8]

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

func prefix(while: (UInt8) -> Bool) -> [UInt8]

Returns a sequence containing the initial, consecutive elements that satisfy the given predicate.

func suffix(Int) -> [UInt8]

Returns a subsequence, up to the given maximum length, containing the final elements of the sequence.