Skip to content

Kotlin functional programming extensions for Reactor

License

Notifications You must be signed in to change notification settings

cobaltinc/vortex

Repository files navigation

Vortex 🌪️

Kotlin functional extensions for Spring Webflux

Latest version PRs welcome

🚀 Getting started

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")

✨ Usecase

Condition

throwIf

Mono
  .just(inputNumber)
  .throwIf(Exception("Only take odd numbers")) { it % 2 == 0 }

Or,

this.userRepository
  .findById(userId)
  .throwIf(Exception("Banned user")) { it.banned }

iif

Mono
  .just(inputNumber)
  .iif(Mono.just("Even"), Mono.just("Odd")) { it % 2 == 0 }

Pipe

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() }
)

Function Composite

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
  )

📄 License

Vortex is made available under the MIT License.

About

Kotlin functional programming extensions for Reactor

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages