-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kotlin extensions for core and test now next to java code
This commit pulls down kotlin extensions for core and test into the original java project instead of a separate project/artifact.
- Loading branch information
1 parent
1ce7848
commit 5140235
Showing
12 changed files
with
1,223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
reactor-core/src/main/java/reactor/core/publisher/MonoBridges.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2011-2017 Pivotal Software Inc, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package reactor.core.publisher; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.reactivestreams.Publisher; | ||
|
||
/** | ||
* Utilities to avoid vararg array copying overhead when relaying vararg parameters | ||
* to underlying Java methods from their corresponding Kotlin functions. | ||
* <p> | ||
* When <a href="https://youtrack.jetbrains.com/issue/KT-17043">this</a> issue is | ||
* resolved, uses of these bridge methods can be removed. | ||
* | ||
* @author DoHyung Kim | ||
* @since 3.1 | ||
*/ | ||
class MonoBridges { | ||
|
||
static Mono<Void> when(Publisher<Void>[] sources) { | ||
return Mono.when(sources); | ||
} | ||
|
||
static <R> Mono<R> when(Function<? super Object[], ? extends R> combinator, Mono<?>[] monos) { | ||
return Mono.when(combinator, monos); | ||
} | ||
|
||
private MonoBridges() { | ||
// Not to be instantiated | ||
} | ||
} |
185 changes: 185 additions & 0 deletions
185
reactor-core/src/main/kotlin/reactor/core/publisher/FluxExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* | ||
* Copyright (c) 2011-2017 Pivotal Software Inc, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package reactor.core.publisher | ||
|
||
import org.reactivestreams.Publisher | ||
import java.util.stream.Stream | ||
import kotlin.reflect.KClass | ||
|
||
|
||
/** | ||
* Extension for transforming an [Iterator] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T> Iterator<T>.toFlux(): Flux<T> = toIterable().toFlux() | ||
|
||
/** | ||
* Extension for transforming an [Iterable] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T> Iterable<T>.toFlux(): Flux<T> = Flux.fromIterable(this) | ||
|
||
/** | ||
* Extension for transforming a [Sequence] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T> Sequence<T>.toFlux(): Flux<T> = Flux.fromIterable(object : Iterable<T> { | ||
override fun iterator(): Iterator<T> = this@toFlux.iterator() | ||
}) | ||
|
||
/** | ||
* Extension for transforming a [Stream] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T> Stream<T>.toFlux(): Flux<T> = Flux.fromStream(this) | ||
|
||
/** | ||
* Extension for transforming a [BooleanArray] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun BooleanArray.toFlux(): Flux<Boolean> = this.toList().toFlux() | ||
|
||
/** | ||
* Extension for transforming a [ByteArray] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun ByteArray.toFlux(): Flux<Byte> = this.toList().toFlux() | ||
|
||
/** | ||
* Extension for transforming a [ShortArray] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun ShortArray.toFlux(): Flux<Short> = this.toList().toFlux() | ||
|
||
/** | ||
* Extension for transforming a [IntArray] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun IntArray.toFlux(): Flux<Int> = this.toList().toFlux() | ||
|
||
/** | ||
* Extension for transforming a [LongArray] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun LongArray.toFlux(): Flux<Long> = this.toList().toFlux() | ||
|
||
/** | ||
* Extension for transforming a [FloatArray] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun FloatArray.toFlux(): Flux<Float> = this.toList().toFlux() | ||
|
||
/** | ||
* Extension for transforming a [DoubleArray] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun DoubleArray.toFlux(): Flux<Double> = this.toList().toFlux() | ||
|
||
/** | ||
* Extension for transforming an [Array] to a [Flux]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T> Array<out T>.toFlux(): Flux<T> = Flux.fromArray(this) | ||
|
||
private fun <T> Iterator<T>.toIterable() = object : Iterable<T> { | ||
override fun iterator(): Iterator<T> = this@toIterable | ||
} | ||
|
||
/** | ||
* Extension for transforming an exception to a [Flux] that completes with the specified error. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T> Throwable.toFlux(): Flux<T> = Flux.error(this) | ||
|
||
/** | ||
* Extension for [Flux.cast] providing a `cast<Foo>()` variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
inline fun <reified T : Any> Flux<*>.cast(): Flux<T> = cast(T::class.java) | ||
|
||
|
||
/** | ||
* Extension for [Flux.doOnError] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T, E : Throwable> Flux<T>.doOnError(exceptionType: KClass<E>, onError: (E) -> Unit): Flux<T> = | ||
doOnError(exceptionType.java, { onError(it) }) | ||
|
||
/** | ||
* Extension for [Flux.onErrorMap] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T, E : Throwable> Flux<T>.onErrorMap(exceptionType: KClass<E>, mapper: (E) -> Throwable): Flux<T> = | ||
onErrorMap(exceptionType.java, { mapper(it) }) | ||
|
||
/** | ||
* Extension for [Flux.ofType] providing a `ofType<Foo>()` variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
inline fun <reified T : Any> Flux<*>.ofType(): Flux<T> = ofType(T::class.java) | ||
|
||
/** | ||
* Extension for [Flux.onErrorResume] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T : Any, E : Throwable> Flux<T>.onErrorResume(exceptionType: KClass<E>, fallback: (E) -> Publisher<T>): Flux<T> = | ||
onErrorResume(exceptionType.java, { fallback(it) }) | ||
|
||
/** | ||
* Extension for [Flux.onErrorReturn] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T : Any, E : Throwable> Flux<T>.onErrorReturn(exceptionType: KClass<E>, value: T): Flux<T> = | ||
onErrorReturn(exceptionType.java, value) |
106 changes: 106 additions & 0 deletions
106
reactor-core/src/main/kotlin/reactor/core/publisher/MonoExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) 2011-2017 Pivotal Software Inc, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package reactor.core.publisher | ||
|
||
import java.util.concurrent.Callable | ||
import java.util.concurrent.CompletableFuture | ||
import kotlin.reflect.KClass | ||
|
||
|
||
/** | ||
* Extension for transforming an object to a [Mono]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T> T.toMono(): Mono<T> = Mono.just(this) | ||
|
||
/** | ||
* Extension for transforming an [CompletableFuture] to a [Mono]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T> CompletableFuture<T>.toMono(): Mono<T> = Mono.fromFuture(this) | ||
|
||
/** | ||
* Extension for transforming an [Callable] to a [Mono]. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T> Callable<T>.toMono(): Mono<T> = Mono.fromCallable(this::call) | ||
|
||
/** | ||
* Extension for transforming an exception to a [Mono] that completes with the specified error. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T> Throwable.toMono(): Mono<T> = Mono.error(this) | ||
|
||
/** | ||
* Extension for [Mono.cast] providing a `cast<Foo>()` variant. | ||
* | ||
* @author Sebastien | ||
* @since 3.1 | ||
*/ | ||
inline fun <reified T : Any> Mono<*>.cast(): Mono<T> = cast(T::class.java) | ||
|
||
/** | ||
* Extension for [Mono.doOnError] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T, E : Throwable> Mono<T>.doOnError(exceptionType: KClass<E>, onError: (E) -> Unit): Mono<T> = | ||
doOnError(exceptionType.java, { onError(it) }) | ||
|
||
/** | ||
* Extension for [Mono.onErrorMap] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T, E : Throwable> Mono<T>.onErrorMap(exceptionType: KClass<E>, mapper: (E) -> Throwable): Mono<T> = | ||
onErrorMap(exceptionType.java, { mapper(it) }) | ||
|
||
/** | ||
* Extension for [Mono.ofType] providing a `ofType<Foo>()` variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
inline fun <reified T : Any> Mono<*>.ofType(): Mono<T> = ofType(T::class.java) | ||
|
||
/** | ||
* Extension for [Mono.onErrorResume] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T : Any, E : Throwable> Mono<T>.onErrorResume(exceptionType: KClass<E>, fallback: (E) -> Mono<T>): Mono<T> = | ||
onErrorResume(exceptionType.java, { fallback(it) }) | ||
|
||
/** | ||
* Extension for [Mono.onErrorReturn] providing a [KClass] based variant. | ||
* | ||
* @author Sebastien Deleuze | ||
* @since 3.1 | ||
*/ | ||
fun <T : Any, E : Throwable> Mono<T>.onErrorReturn(exceptionType: KClass<E>, value: T): Mono<T> = | ||
onErrorReturn(exceptionType.java, value) |
Oops, something went wrong.