liveBook · Manning

fromStream

As explained in Spring in Action, Sixth Edition

fromStream is a Project Reactor factory operation that creates a Flux from the elements of a Java Stream.

fromStream creates a Project Reactor Flux from a Java Stream, publishing the stream’s elements as reactive data. section 11.3.1

@Test
 public void createAFlux_fromStream() {
   Stream<String> fruitStream = 
        Stream.of("Apple", "Orange", "Grape", "Banana", "Strawberry");
   Flux<String> fruitFlux = Flux.fromStream(fruitStream);
    
   StepVerifier.create(fruitFlux)
       .expectNext("Apple")
       .expectNext("Orange")
       .expectNext("Grape")
       .expectNext("Banana")
       .expectNext("Strawberry")
       .verifyComplete();
 }

Build a fruit Stream, pass it to Flux.fromStream(), and verify the published values with StepVerifier. section 11.3.1

Fruit stream

The example emits Apple, Orange, Grape, Banana, and Strawberry in order, then verifies that the Flux completes. section 11.3.1

How Spring in Action, Sixth Edition covers it

How deep it goes
Demonstrates construction and completion verification with a complete Java test method.
Examples
Uses a fruit Stream containing Apple, Orange, Grape, Banana, and Strawberry.
What it assumes
Assumes Java Stream, Flux, and StepVerifier terminology.
What you can do after
Build it from scratch by converting a Java Stream into a Flux and verifying its emitted elements.
How it connects
Connects Java Stream with Flux creation and StepVerifier-based testing.

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.