Close

Reactor - Mapping items

[Last Updated: Aug 11, 2020]

Following synchronous function are used to transform the items emitted by Flux and Mono

Class Flux

public final <V> Flux<V> map(Function<? super T,? extends V> mapper)

Class Mono

public final <R> Mono<R> map(Function<? super T,? extends R> mapper)

Example

public class MapOperationExample {
  public static void main(String[] args) {
      System.out.println("-- Mapping Flux elements --");
      Flux.just(2, 4, 6, 8)
          .map(n -> n / 2)
          .subscribe(System.out::println);

      System.out.println("-- Mapping Mono element --");
      Mono.just("supercalifragilisticexpialidocious")
          .map(s -> s.length())
          .subscribe(System.out::println);
  }
}
-- Mapping Flux elements --
1
2
3
4
-- Mapping Mono element --
34

Example Project

Dependencies and Technologies Used:

  • reactor-core 3.3.2.RELEASE: Non-Blocking Reactive Foundation for the JVM.
  • JDK 8
  • Maven 3.5.4

Reactor map() examples Select All Download
  • reactor-map-operation
    • src
      • main
        • java
          • com
            • logicbig
              • example
                • MapOperationExample.java

    See Also