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

dropFirst(_:)

Returns a sequence containing all but the given number of initial elements. 指定された数の冒頭要素以外すべてを含んでいるあるシーケンスを返します。

Declaration 宣言

func dropFirst(_ k: Int = 1) -> DropFirstSequence<LazyFilterSequence<Base>.Iterator>

Parameters パラメータ

k

The number of elements to drop from the beginning of the sequence. k must be greater than or equal to zero. このシーケンスの初めの部分から落とす要素の数。kは、ゼロより大きいか等しくなければなりません。

Return Value 戻り値

A sequence starting after the specified number of elements. 指定された数の要素の後で始まるシーケンス。

Discussion 解説

If the number of elements to drop exceeds the number of elements in the sequence, the result is an empty sequence. 取り除く要素の数がシーケンスの要素数を越えるならば、結果は空のシーケンスです。


let numbers = [1, 2, 3, 4, 5]
print(numbers.dropFirst(2))
// Prints "[3, 4, 5]"
print(numbers.dropFirst(10))
// Prints "[]"

Complexity: O(1), with O(k) deferred to each iteration of the result, where k is the number of elements to drop from the beginning of the sequence. 計算量:O(1)、結果の各反復に対してO(k)延期されて、ここでkはシーケンスの冒頭から除かれる要素の数です。