Reactor Kotlin Extensions 1.0.0.M1 发布
更新:Kotlin 现在已由 reactor-core
和 reactor-test
原生支持,无需任何额外扩展。
我很高兴地宣布 Reactor Kotlin Extensions 的第一个里程碑版本已发布,它为 Reactor API 提供了 Kotlin 扩展。
它提供了对 KClass
等 Kotlin 类型的支持,利用了 Kotlin 的具体化类型参数(reified type parameters),并提供了各种扩展以实现更富有表现力的代码。您可以在下方看到 Reactor 与 Java 以及 Reactor 与 Kotlin + 扩展的快速比较。
Java | 带有扩展的 Kotlin |
---|---|
Mono.just("foo") |
"foo".toMono() |
Flux.fromIterable(list) |
list.toFlux() |
Mono.error(new RuntimeException()) |
RuntimeException().toMono() |
Flux.error(new RuntimeException()) |
RuntimeException().toFlux() |
flux.ofType(Foo.class) |
flux.ofType<Foo>() 或 flux.ofType(Foo::class) |
StepVerifier.create(flux).verifyComplete() |
flux.test().verifyComplete() |