Reactor Kotlin Extensions

repository·main·Indexed 41 days ago

https://github.com/reactor/reactor-kotlin-extensions

Specialized extensions and adapters for Project Reactor that make the functional programming API more idiomatic and ergonomic for Kotlin developers. Features include support for destructuring Tuples, converting collections to Flux via .toFlux(), and coordinating Mono completion with whenComplete.

Tokens
580
Snippets
5
Records
5
Agent score
50%

What's inside Reactor Kotlin Extensions

  1. Install Reactor Kotlin Extensions via Maven

    main

    To use the stable release in a Maven project, add the following dependency to your pom.xml using Maven Central.

    <dependency>
        <groupId>io.projectreactor.kotlin</groupId>
        <artifactId>reactor-kotlin-extensions</artifactId>
        <version>1.3.2</version>
    </dependency>
  2. Install Reactor Kotlin Extensions

    main

    You can add Reactor Kotlin Extensions to your project using Gradle or Maven. Stable releases are available via Maven Central. Snapshot versions can be obtained from the Spring repositories.

        repositories {
            mavenCentral()
        }
    
        dependencies {
            implementation "io.projectreactor.kotlin:reactor-kotlin-extensions:1.3.2"
        }
  3. Convert Collections to Flux and perform operations

    main

    Use .toFlux() to convert standard Kotlin/Java collections (like IntArray) into a Reactor Flux. Note that certain operations like .sum() may require reactor-extra, and testing utilities like .test() require reactor-test.

    intArrayOf(2_000_000_000, 200_000_000) //sum overflows an Int
        .toFlux()
        .sum()
        .test()
        .expectNext(2_200_000_000)
        .verifyComplete()
  4. Coordinate completion of two Monos with whenComplete

    main

    The whenComplete extension function allows you to coordinate the completion of two separate Mono instances. It returns a Mono that completes only when both input Monos have completed.

    whenComplete("foo1".toMono(), "foo2".toMono())
        .test()
        .verifyComplete()