實例方法
drop(while:)
通過跳過滿足給定謂詞的初始連續元素返回一個序列。
聲明
func drop(while predicate: (Self.Element) throws -> Bool) rethrows -> DropWhileSequence<Self>
返回值
在滿足 predicate
的初始連續元素之後開始的序列。
參數
predicate
一個閉包,它將序列的一個元素作為其參數,並返回一個布爾值,指示該元素是否應包含在結果中。
詳述
以下示例使用 drop(while:)
方法跳過 numbers
數組開頭的正數。結果從不滿足 predicate
的 numbers
的第一個元素開始。
let numbers = [3, 7, 4, -2, 9, -6, 10, 1]
let startingWithNegative = numbers.drop(while: { $0 > 0 })
// startingWithNegative == [-2, 9, -6, 10, 1]
如果predicate
匹配序列中的每個元素,則結果為空序列。
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相關用法
- Swift Zip2Sequence dropFirst(_:)用法及代碼示例
- Swift Zip2Sequence dropLast(_:)用法及代碼示例
- Swift Zip2Sequence max(by:)用法及代碼示例
- Swift Zip2Sequence shuffled(using:)用法及代碼示例
- Swift Zip2Sequence allSatisfy(_:)用法及代碼示例
- Swift Zip2Sequence reduce(into:_:)用法及代碼示例
- Swift Zip2Sequence shuffled()用法及代碼示例
- Swift Zip2Sequence compactMap(_:)用法及代碼示例
- Swift Zip2Sequence suffix(_:)用法及代碼示例
- Swift Zip2Sequence filter(_:)用法及代碼示例
- Swift Zip2Sequence forEach(_:)用法及代碼示例
- Swift Zip2Sequence sorted(by:)用法及代碼示例
- Swift Zip2Sequence prefix(_:)用法及代碼示例
- Swift Zip2Sequence min(by:)用法及代碼示例
- Swift Zip2Sequence first(where:)用法及代碼示例
- Swift Zip2Sequence prefix(while:)用法及代碼示例
- Swift Zip2Sequence split(maxSplits:omittingEmptySubsequences:whereSeparator:)用法及代碼示例
- Swift Zip2Sequence flatMap(_:)用法及代碼示例
- Swift Zip2Sequence map(_:)用法及代碼示例
- Swift Zip2Sequence contains(where:)用法及代碼示例
- Swift Zip2Sequence enumerated()用法及代碼示例
- Swift Zip2Sequence reduce(_:_:)用法及代碼示例
- Swift Zip2Sequence用法及代碼示例
- Swift KeyValuePairs flatMap(_:)用法及代碼示例
- Swift String.UTF8View first用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Zip2Sequence drop(while:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。