Kotlin functional extensions for Spring Webflux
depend via Maven:
<dependency>
<groupId>run.cobalt</groupId>
<artifactId>vortex</artifactId>
<version>0.0.2</version>
</dependency>
or Gradle:
implementation("run.cobalt:vortex:0.0.2")
Mono
.just(inputNumber)
.throwIf(Exception("Only take odd numbers")) { it % 2 == 0 }
Or,
this.userRepository
.findById(userId)
.throwIf(Exception("Banned user")) { it.banned }
Mono
.just(inputNumber)
.iif(Mono.just("Even"), Mono.just("Odd")) { it % 2 == 0 }
Flux
.fromIterable(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
.pipe(
MonoExt.filter { it % 2 == 0 },
MonoExt.reduce { t, t2 -> t + t2 }
MonoExt.map { it.toString() }
)
Or,
pipe(
Flux.fromIterable(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
FluxExt.filter { it % 2 == 0 },
FluxExt.reduce { t, t2 -> t + t2 }
MonoExt.map { it.toString() }
)
val sumToString = FluxExt.reduce<Int> { a, b -> a + b } then MonoExt.map { it.toString() }
Flux
.fromIterable(listOf(1, 2, 3, 4, 5))
.pipe(
FluxExt.map { it.inc() },
sumToString
)
Vortex is made available under the MIT License.