Contents

dropFirst(_:)

Omits the specified number of elements before republishing subsequent elements.

Declaration

func dropFirst(_ count: Int = 1) -> Publishers.Drop<Self>

Parameters

  • count:

    The number of elements to omit. The default is 1.

Return Value

A publisher that doesn’t republish the first count elements.

Discussion

Use dropFirst(_:) when you want to drop the first n elements from the upstream publisher, and republish the remaining elements.

The example below drops the first five elements from the stream:

let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
cancellable = numbers.publisher
    .dropFirst(5)
    .sink { print("\($0)", terminator: " ") }

// Prints: "6 7 8 9 10 "

See Also

Applying sequence operations to elements