實例方法
drop
dropFirst(_:)
在重新發布後續元素之前省略指定數量的元素。
聲明
func dropFirst(_ count: Int = 1) -> Publishers.Drop<Self>
返回值
不重新發布第一個 count
元素的發布者。
參數
count
要省略的元素數。默認值為
1
。
詳述
當您想從上遊發布者中刪除第一個 n
元素並重新發布其餘元素時,請使用 Publisher/dropFirst(_:)
。
下麵的示例從流中刪除前五個元素:
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
cancellable = numbers.publisher
.dropFirst(5)
.sink { print("\($0)", terminator: " ") }
// Prints: "6 7 8 9 10 "
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Result.Publisher drop(while:)用法及代碼示例
- Swift Result.Publisher drop(untilOutputFrom:)用法及代碼示例
- 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 dropFirst(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。