reactor / reactor-kotlin-extensions

Reactor Kotlin Support
Apache License 2.0
142 stars 21 forks source link

Enabling out with generics for extension test() #60

Open sylvain-barrepersyn opened 1 year ago

sylvain-barrepersyn commented 1 year ago

Motivation

Enabling out with generics for extension test().

fun aMono(): Mono<out CharSequence> {
    return Mono.just("Hello")
}
StepVerifier.create(aMono())
    .expectNext(
        "Hello" // OK
    )
    .verifyComplete()
aMono()
    .test()
    .expectNext(
        "Hello" // Compilation error
    )
    .verifyComplete()

Desired solution

It can be good to accept generics. Maybe a modification like this can be added ?

Example of modification:

           // ↓ add `out`
fun <T> Flux<out T>.test(): StepVerifier.FirstStep<T> = StepVerifier.create(this)

Considered alternatives

Additional context

StepVerifierExtensions

/**
 * Extension for testing [Flux] with [StepVerifier] API.
 *
 * @author Sebastien Deleuze
 */
fun <T> Flux<T>.test(): StepVerifier.FirstStep<T> = StepVerifier.create(this)

/**
 * Extension for testing [Flux] with [StepVerifier] API.
 *
 * @author Sebastien Deleuze
 */
fun <T> Flux<T>.test(n: Long): StepVerifier.FirstStep<T> = StepVerifier.create(this, n)

/**
 * Extension for testing [Flux] with [StepVerifier] API.
 *
 * @author Cristian Romero
 */
fun <T> Flux<T>.test(options: StepVerifierOptions): StepVerifier.FirstStep<T> = StepVerifier.create(this, options)

/**
 * Extension for testing [Mono] with [StepVerifier] API.
 *
 * @author Sebastien Deleuze
 */
fun <T> Mono<T>.test(): StepVerifier.FirstStep<T> = StepVerifier.create(this)

/**
 * Extension for testing [Mono] with [StepVerifier] API.
 *
 * @author Sebastien Deleuze
 */
fun <T> Mono<T>.test(n: Long): StepVerifier.FirstStep<T> = StepVerifier.create(this, n)

/**
 * Extension for testing [Mono] with [StepVerifier] API.
 *
 * @author Cristian Romero
 */
fun <T> Mono<T>.test(options: StepVerifierOptions): StepVerifier.FirstStep<T> = StepVerifier.create(this, options)