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

drop(while:)

Omits elements from the base asynchronous sequence until a given closure returns false, after which it passes through all remaining elements. 要素を基底非同期シーケンスから、ある与えられたクロージャがfalseを返すまで省きます、それの後それは全ての残りの要素をずっと渡します。

Declaration 宣言

func drop(while predicate: @escaping (Element) async -> Bool) -> AsyncDropWhileSequence<AsyncThrowingStream<Element, Failure>>

Parameters パラメータ

predicate

A closure that takes an element as a parameter and returns a Boolean value indicating whether to drop the element from the modified sequence. あるクロージャ、それはある要素をパラメータとして取り、その要素をこの修正後のシーケンスから抜かすことになるかどうかを指し示すブール値を返すものです。

Return Value 戻り値

An asynchronous sequence that skips over values from the base sequence until the provided closure returns false. ある非同期シーケンス、それは基底シーケンスから値それらを、この提供されたクロージャがfalseを返すまで飛び越えるものです。

Discussion 解説

Use drop(while:) to omit elements from an asynchronous sequence until the element received meets a condition you specify. drop(while:)を使うことで要素を非同期シーケンスから、その受け取った要素があなたが指定する条件に合うまで省いてください。

In this example, an asynchronous sequence called Counter produces Int values from 1 to 10. The drop(while:) method causes the modified sequence to ignore received values until it encounters one that is divisible by 3: この例において、Counterと呼ばれる非同期シーケンスはInt値を1から10まで生み出します。drop(while:)メソッドは、修正されたシーケンスが、それが3によって割り切れるものに出くわすまで受け取った値を無視することを引き起こします:


let stream = Counter(howHigh: 10)
    .drop { $0 % 3 != 0 }
for await number in stream {
    print("\(number) ", terminator: " ")
}
// prints "3 4 5 6 7 8 9 10"

After the predicate returns false, the sequence never executes it again, and from then on the sequence passes through elements from its underlying sequence as-is. 述部がfalseを返した後、シーケンスはそれを決して再び遂行しません、そしてそれからシーケンス上では、要素それらをそれの基礎をなすシーケンスからそのままでずっと渡します。

See Also 参照

Excluding Elements 要素を除外する