Instance Method インスタンスメソッド

filter(_:)

Creates an asynchronous sequence that contains, in order, the elements of the base sequence that satisfy the given predicate. ある非同期シーケンスを作成します、それは基底シーケンスの要素それらを、順番に含みます、それらは与えられた述部を満たすものです。

Declaration 宣言

func filter(_ isIncluded: @escaping (Element) async -> Bool) -> AsyncFilterSequence<AsyncThrowingStream<Element, Failure>>

Parameters パラメータ

isIncluded

A closure that takes an element of the asynchronous sequence as its argument and returns a Boolean value that indicates whether to include the element in the filtered sequence. あるクロージャ、それは非同期シーケンスの1つの要素をそれの引数として取り、その要素をこの平坦化されたシーケンスに含むことになるかどうかを指し示すブール値を返します。

Return Value 戻り値

An asynchronous sequence that contains, in order, the elements of the base sequence that satisfy the given predicate. ある非同期シーケンス、それは基底シーケンスの要素それらを、順番に含みます、それらは与えられた述部を満たすものです。

Discussion 解説

In this example, an asynchronous sequence called Counter produces Int values from 1 to 10. The filter(_:) method returns true for even values and false for odd values, thereby filtering out the odd values: この例において、Counterと呼ばれる非同期シーケンスはInt値を1から10まで生み出します。filter(_:)メソッドは、trueを偶数値に対してそしてfalseを奇数値に対して返します、それによって奇数値を取り除いています:


let stream = Counter(howHigh: 10)
    .filter { $0 % 2 == 0 }
for await number in stream {
    print("\(number) ", terminator: " ")
}
// Prints: 2  4  6  8  10

See Also 参照

Excluding Elements 要素を除外する