liveBook · Manning

Skip

As explained in Spring in Action, Sixth Edition

skip is a Project Reactor operator that suppresses a specified number of source elements or elements emitted before a specified duration.

`skip()` filters the beginning of a Project Reactor `Flux`. Give it an item count to discard that many source elements; the resulting `Flux` emits the rest. section 11.3.3

@Test
public void skipAFew() {
  Flux<String> countFlux = Flux.just(
      "one", "two", "skip a few", "ninety nine", "one hundred")
      .skip(3);
  
  StepVerifier.create(countFlux)
      .expectNext("ninety nine", "one hundred")
      .verifyComplete();
}

In this test, `skip(3)` drops the first three strings. `StepVerifier` checks that only the final two are emitted. section 11.3.3

To skip by time instead, pass a `Duration`. With elements delayed one second apart, `skip(Duration.ofSeconds(4))` leaves the final two strings. Use `take()` for the opposite choice: emitting the first items rather than skipping them. section 11.3.3

@Test
public void skipAFewSeconds() {
  Flux<String> countFlux = Flux.just(
      "one", "two", "skip a few", "ninety nine", "one hundred")
      .delayElements(Duration.ofSeconds(1))
      .skip(Duration.ofSeconds(4));
  
  StepVerifier.create(countFlux)
      .expectNext("ninety nine", "one hundred")
      .verifyComplete();
}

The timed test combines `delayElements()`, `skip(Duration.ofSeconds(4))`, and `StepVerifier` to check what remains. section 11.3.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains count-based and duration-based forms through tests, without detailing operator internals.
Examples
Tests five-string Fluxes that skip three items or wait four seconds before emitting.
What it assumes
Assumes basic Java and Flux familiarity while demonstrating skip with Flux.just and StepVerifier.
What you can do after
Apply it via Project Reactor Flux.skip to discard initial items or a timed interval and verify the result with StepVerifier.
How it connects
Connects skip to Flux, delayElements, StepVerifier, and the contrasting take operator.

Also explained in

Compare how 2 books explain skip →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.