Returns a subsequence containing the initial elements until predicate returns false and skipping the remaining elements.
SDK
- Xcode 11.0+
Framework
- Swift Standard Library
Declaration
func prefix(while predicate: (CollectionDifference <ChangeElement>.Change) throws -> Bool) rethrows -> Slice<CollectionDifference <ChangeElement>>
Parameters
predicateA closure that takes an element of the sequence as its argument and returns
trueif the element should be included orfalseif it should be excluded. Once the predicate returnsfalseit will not be called again.
Discussion
Complexity: O(n), where n is the length of the collection.