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

drop(while:)

Returns a sequence by skipping the initial, consecutive elements that satisfy the given predicate. 与えられた述部を満たす、冒頭の、隣接する要素を飛ばすことによるあるシーケンスを返します。

Declaration 宣言

func drop(while predicate: (Base.Element) throws -> Bool) rethrows -> DropWhileSequence<LazyFilterSequence<Base>.Iterator>

Parameters パラメータ

predicate

A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element should be included in the result. あるクロージャ、それはシーケンスの1つの要素をそれの引数として取り、その要素が結果に含まれるべきかどうかを指し示しているブール値を返します。

Return Value 戻り値

A sequence starting after the initial, consecutive elements that satisfy predicate. predicateを満たす冒頭の、隣接する要素の後で始まるあるシーケンス。

Discussion 解説

The following example uses the drop(while:) method to skip over the positive numbers at the beginning of the numbers array. The result begins with the first element of numbers that does not satisfy predicate. 以下の例は、drop(while:)メソッドを使って、正の数をnumbers配列の始まりで省きます。結果は、predicateを満たさない、numbersの最初の要素で始まります。


let numbers = [3, 7, 4, -2, 9, -6, 10, 1]
let startingWithNegative = numbers.drop(while: { $0 > 0 })
// startingWithNegative == [-2, 9, -6, 10, 1]

If predicate matches every element in the sequence, the result is an empty sequence. predicateがシーケンスの中のすべての要素に合致するならば、結果は空のシーケンスです。

Complexity: O(k), where k is the number of elements to drop from the beginning of the sequence. 計算量:O(k)、ここでkはシーケンスの冒頭から除かれる要素の数です。