实例方法
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(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。