實例方法
drop(while:)
在重新發布所有剩餘元素之前,忽略上遊發布者的元素,直到給定的閉包返回 false。
聲明
func drop(while predicate: @escaping (Self.Output) -> Bool) -> Publishers.DropWhile<Self>
返回值
跳過元素直到提供的閉包返回 false
的發布者。
參數
predicate
一個閉包,它接受一個元素作為參數並返回一個布爾值,指示是否從發布者的輸出中刪除該元素。
詳述
使用Publisher/drop(while:)
省略來自上遊發布者的元素,直到收到的元素滿足您指定的條件。
在下麵的示例中,運算符會省略流中的所有元素,直到第一個正整數元素到達,之後運算符會發布所有剩餘元素:
let numbers = [-62, -1, 0, 10, 0, 22, 41, -1, 5]
cancellable = numbers.publisher
.drop { $0 <= 0 }
.sink { print("\($0)") }
// Prints: "10 0, 22 41 -1 5"
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Result.Publisher drop(untilOutputFrom:)用法及代碼示例
- Swift Result.Publisher dropFirst(_:)用法及代碼示例
- Swift Result.Publisher debounce(for:scheduler:options:)用法及代碼示例
- Swift Result.Publisher decode(type:decoder:)用法及代碼示例
- Swift Result.Publisher delay(for:tolerance:scheduler:options:)用法及代碼示例
- Swift Result.Publisher zip(_:_:_:)用法及代碼示例
- Swift Result.Publisher tryLast(where:)用法及代碼示例
- Swift Result.Publisher sink(receiveCompletion:receiveValue:)用法及代碼示例
- Swift Result.Publisher merge(with:_:_:)用法及代碼示例
- Swift Result.Publisher tryCompactMap(_:)用法及代碼示例
- Swift Result.Publisher print(_:to:)用法及代碼示例
- Swift Result.Publisher sink(receiveValue:)用法及代碼示例
- Swift Result.Publisher eraseToAnyPublisher()用法及代碼示例
- Swift Result.Publisher setFailureType(to:)用法及代碼示例
- Swift Result.Publisher first(where:)用法及代碼示例
- Swift Result.Publisher output(at:)用法及代碼示例
- Swift Result.Publisher tryCatch(_:)用法及代碼示例
- Swift Result.Publisher merge(with:_:_:_:_:_:_:)用法及代碼示例
- Swift Result.Publisher flatMap(maxPublishers:_:)用法及代碼示例
- Swift Result.Publisher map(_:_:_:)用法及代碼示例
- Swift Result.Publisher catch(_:)用法及代碼示例
- Swift Result.Publisher prefix(_:)用法及代碼示例
- Swift Result.Publisher timeout(_:scheduler:options:customError:)用法及代碼示例
- Swift Result.Publisher merge(with:_:)用法及代碼示例
- Swift Result.Publisher map(_:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Result.Publisher drop(while:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。