实例方法
contains(_:)
返回一个布尔值,指示异步序列是否包含给定元素。
声明
func contains(_ search: Self.Element) async rethrows -> Bool
当
Element
符合 Equatable
时可用。返回值
true
如果方法找到异步序列中的元素;否则,false
。
参数
search
要在异步序列中查找的元素。
详述
在此示例中,名为 Counter
的异步序列生成从 1
到 10
的 Int
值。 contains(_:)
方法检查序列是否产生值 5
:
let containsFive = await Counter(howHigh: 10)
.contains(5)
print(containsFive)
// Prints: true
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相关用法
- Swift AsyncThrowingPrefixWhileSequence contains(where:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence compactMap(_:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence drop(while:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence filter(_:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence flatMap(_:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence reduce(_:_:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence allSatisfy(_:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence max(by:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence dropFirst(_:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence max()用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence prefix(_:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence map(_:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence prefix(while:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence first(where:)用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence min()用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence min(by:)用法及代码示例
- Swift AsyncThrowingFlatMapSequence min()用法及代码示例
- Swift AsyncThrowingMapSequence reduce(_:_:)用法及代码示例
- Swift AsyncThrowingMapSequence contains(_:)用法及代码示例
- Swift AsyncThrowingDropWhileSequence first(where:)用法及代码示例
- Swift AsyncThrowingCompactMapSequence drop(while:)用法及代码示例
- Swift AsyncThrowingFilterSequence drop(while:)用法及代码示例
- Swift AsyncThrowingCompactMapSequence prefix(while:)用法及代码示例
- Swift AsyncThrowingDropWhileSequence flatMap(_:)用法及代码示例
- Swift AsyncThrowingStream filter(_:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 AsyncThrowingPrefixWhileSequence contains(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。