實例方法
all
allSatisfy(_:)
返回一個布爾值,該值指示異步序列生成的所有元素是否滿足給定謂詞。
聲明
func allSatisfy(_ predicate: (Self.Element) async throws -> Bool) async rethrows -> Bool
返回值
true
如果序列僅包含滿足 predicate
的元素;否則,false
。
參數
predicate
一個閉包,它將異步序列的元素作為其參數並返回一個布爾值,該值指示傳遞的元素是否滿足條件。
詳述
在此示例中,名為 Counter
的異步序列生成從 1
到 10
的 Int
值。 allSatisfy(_:)
方法檢查序列生成的所有元素是否小於 10
。
let allLessThanTen = await Counter(howHigh: 10)
.allSatisfy { $0 < 10 }
print(allLessThanTen)
// Prints: false
每次異步序列產生一個元素時都會執行謂詞,直到謂詞返回false
或序列結束。
如果異步序列為空,則此方法返回 true
。
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift AsyncThrowingPrefixWhileSequence drop(while:)用法及代碼示例
- Swift AsyncThrowingPrefixWhileSequence filter(_:)用法及代碼示例
- Swift AsyncThrowingPrefixWhileSequence compactMap(_:)用法及代碼示例
- Swift AsyncThrowingPrefixWhileSequence flatMap(_:)用法及代碼示例
- Swift AsyncThrowingPrefixWhileSequence reduce(_:_:)用法及代碼示例
- 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 contains(where:)用法及代碼示例
- Swift AsyncThrowingPrefixWhileSequence contains(_:)用法及代碼示例
- 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 allSatisfy(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。