Package-level declarations

Types

Link copied to clipboard
interface Single<out T> : Source<SingleObserver<T>>

Represents a Source that can complete with a value or produce an error.

Link copied to clipboard

Callbacks for Single source. See Single, SuccessCallback and ErrorCallback for more information.

Link copied to clipboard

Represents an emitter for Single source. See Emitter and SingleCallbacks for more information.

Link copied to clipboard

Represents an Observer of Single source. See Observer and SingleCallbacks for more information.

Link copied to clipboard
open class SingleWrapper<out T : Any>(inner: Single<T>) : Single<T>

Wrappers are normally exposed to Swift. You can also extend the wrapper class if you need to expose any additional operators.

Functions

Link copied to clipboard
fun <T> amb(vararg sources: Single<T>): Single<T>

Runs multiple Singles and signals the events of the first one (disposing the rest).

Link copied to clipboard
fun <T> Iterable<Single<T>>.amb(): Single<T>

Runs multiple Singles and signals the events of the first one to terminate (disposing the rest).

Link copied to clipboard

Returns a Completable that ignores the success value of this Single and signals onComplete instead.

Link copied to clipboard
fun <T> Single<T>.asMaybe(): Maybe<T>

Converts this Single into a Maybe, which signals either onSuccess or onError.

Link copied to clipboard

Converts this Single into an Observable, which signals the success value via onNext followed by onComplete.

Link copied to clipboard
Link copied to clipboard
fun <T> () -> T.asSingle(): Single<T>

A convenience extensions function for singleFromFunction.

Link copied to clipboard
fun <T> Single<T>.blockingGet(): T

Blocks current thread until the current Single succeeds with a value (which is returned) or fails with an exception (which is propagated).

Link copied to clipboard
fun <T> concat(vararg sources: Single<T>): Observable<T>

Concatenates multiple Single sources one by one into an Observable.

Link copied to clipboard

Concatenates multiple Single sources one by one into an Observable.

Link copied to clipboard
fun <T> Single<T>.delay(delay: Duration, scheduler: Scheduler, delayError: Boolean = false): Single<T>

Delays onSuccess signal from the current Single for the specified time. The onError signal is not delayed by default, which can be enabled by setting the delayError flag.

Link copied to clipboard
fun <T> Single<T>.delaySubscription(delay: Duration, scheduler: Scheduler): Single<T>

Delays the actual subscription to the Single for the specified time.

Link copied to clipboard
fun <T> Single<T>.doOnAfterDispose(action: () -> Unit): Single<T>

Calls the shared action when the Disposable sent to the observer via onSubscribe is disposed. The action is called after the upstream is disposed.

Link copied to clipboard
fun <T> Single<T>.doOnAfterError(consumer: (Throwable) -> Unit): Single<T>

Calls the consumer with the emitted Throwable when the Single signals onError. The consumer is called after the observer is called.

Link copied to clipboard
fun <T> Single<T>.doOnAfterFinally(action: () -> Unit): Single<T>

Calls the action when one of the following events occur:

Link copied to clipboard

Calls the shared action for each new observer with the Disposable sent to the downstream. The action is called for each new observer after its onSubscribe callback is called.

Link copied to clipboard
fun <T> Single<T>.doOnAfterSuccess(action: (T) -> Unit): Single<T>

Calls the action with the emitted value when the Single signals onSuccess. The action is called after the observer is called.

Link copied to clipboard
fun <T> Single<T>.doOnAfterTerminate(action: () -> Unit): Single<T>

Calls the action when the Single signals a terminal event: either onSuccess or onError. The action is called after the observer is called.

Link copied to clipboard
fun <T> Single<T>.doOnBeforeDispose(action: () -> Unit): Single<T>

Calls the shared action when the Disposable sent to the observer via onSubscribe is disposed. The action is called before the upstream is disposed.

Link copied to clipboard
fun <T> Single<T>.doOnBeforeError(consumer: (Throwable) -> Unit): Single<T>

Calls the consumer with the emitted Throwable when the Single signals onError. The consumer is called before the observer is called.

Link copied to clipboard
fun <T> Single<T>.doOnBeforeFinally(action: () -> Unit): Single<T>

Calls the action when one of the following events occur:

Link copied to clipboard

Calls the shared action for each new observer with the Disposable sent to the downstream. The action is called for each new observer before its onSubscribe callback is called.

Link copied to clipboard
fun <T> Single<T>.doOnBeforeSuccess(consumer: (T) -> Unit): Single<T>

Calls the consumer with the emitted value when the Single signals onSuccess. The consumer is called before the observer is called.

Link copied to clipboard
fun <T> Single<T>.doOnBeforeTerminate(action: () -> Unit): Single<T>

Calls the action when the Single signals a terminal event: either onSuccess or onError. The action is called before the observer is called.

Link copied to clipboard
fun <T> Single<T>.filter(predicate: (T) -> Boolean): Maybe<T>

Filters the value emitted by the Single using the provided predicate. The returned Maybe signals onSuccess if the predicate returned true, otherwise signals onComplete.

Link copied to clipboard
fun <T, R> Single<T>.flatMap(mapper: (T) -> Single<R>): Single<R>

Calls the mapper with the value emitted by the Single and subscribes to the returned inner Single. Emits the value from the inner Single.

fun <T, U, R> Single<T>.flatMap(resultSelector: (T, U) -> R, mapper: (T) -> Single<U>): Single<R>

Calls the mapper with the value emitted by the Single and subscribes to the returned inner Single. When the inner Single emits, calls the resultSelector function with the original and the inner values and emits the result.

Link copied to clipboard

Calls the mapper with the value emitted by the Single and subscribes to the returned inner Completable.

Link copied to clipboard
fun <T, R> Single<T>.flatMapIterable(transformer: (T) -> Iterable<R>): Observable<R>

Calls the transformer with the value emitted by the Single and emits the returned Iterable values one by one as Observable.

Link copied to clipboard
fun <T, R> Single<T>.flatMapMaybe(mapper: (T) -> Maybe<R>): Maybe<R>

Calls the mapper with the value emitted by the Single and subscribes to the returned inner Maybe. Emits the value from the inner Maybe or completes.

fun <T, U, R> Single<T>.flatMapMaybe(mapper: (T) -> Maybe<U>, resultSelector: (T, U) -> R): Maybe<R>

Calls the mapper with the value emitted by the Single and subscribes to the returned inner Maybe. When the inner Maybe emits, calls the resultSelector function with the original and the inner values and emits the result. Completes if the inner Maybe completed.

Link copied to clipboard
fun <T, R> Single<T>.flatMapObservable(mapper: (T) -> Observable<R>): Observable<R>

Calls the mapper with the value emitted by the Single and subscribes to the returned inner Observable. Emits values from the inner Observable.

fun <T, U, R> Single<T>.flatMapObservable(mapper: (T) -> Observable<U>, resultSelector: (T, U) -> R): Observable<R>

Calls the mapper with the value emitted by the Single and subscribes to the returned inner Observable. For each value emitted by the inner Observable, calls the resultSelector function with the original and the inner values and emits the result.

Link copied to clipboard
@JvmName(name = "flattenObservable")
fun <T> Single<Observable<T>>.flatten(): Observable<T>

This is just a shortcut for Single.flatMapObservable.

When the Single emits an Iterable of values, iterates over the Iterable and emits all values one by one as an Observable.

Link copied to clipboard
fun <T, R> Single<T>.map(mapper: (T) -> R): Single<R>

Converts the value emitted by the Single using the provided mapper and emits the result.

Link copied to clipboard
fun <T, R> Single<Iterable<T>>.mapIterable(mapper: (T) -> R): Single<List<R>>

Converts values of the Iterable emitted by the Single using the provided mapper and emits the resulting values as List.

Link copied to clipboard
fun <T, R, C : MutableCollection<R>> Single<Iterable<T>>.mapIterableTo(collectionSupplier: () -> C, mapper: (T) -> R): Single<C>

Same as mapIterable but saves resulting values into a MutableCollection returned by collectionSupplier.

Link copied to clipboard
fun <T, R : Any> Single<T>.mapNotNull(mapper: (T) -> R?): Maybe<R>

Same as Single.map but returns a Maybe which emits the resulting value only if it is not null, otherwise completes.

Link copied to clipboard
fun <T> merge(vararg sources: Single<T>): Observable<T>

Merges multiple Singles into one Observable, running all Singles simultaneously.

Link copied to clipboard

Merges multiple Singles into one Observable, running all Singles simultaneously.

Link copied to clipboard
fun <T : Any> Single<T?>.notNull(): Maybe<T>

Returns a Maybe that emits the value emitted by this Single only if it is not null, completes otherwise.

Link copied to clipboard
fun <T> Single<T>.observeOn(scheduler: Scheduler): Single<T>

Signals all events of the Single on the specified Scheduler.

Link copied to clipboard
inline fun <T> Single<*>.ofType(): Maybe<T>

Returns Maybe that emits the success value of this Single if it is an instance of T, otherwise completes.

Link copied to clipboard

When the Single signals onError, resumes the flow with next.

fun <T> Single<T>.onErrorResumeNext(nextSupplier: (Throwable) -> Single<T>): Single<T>

When the Single signals onError, resumes the flow with a new Single returned by nextSupplier.

Link copied to clipboard
fun <T> Single<T>.onErrorReturn(valueSupplier: (Throwable) -> T): Single<T>

When the Single signals onError, emits a value returned by valueSupplier.

Link copied to clipboard
fun <T> Single<T>.onErrorReturnValue(value: T): Single<T>

When the Single signals onError, emits the value.

Link copied to clipboard
fun <T> Single<T>.repeat(times: Long = Long.MAX_VALUE): Observable<T>

When the Single signals onSuccess, re-subscribes to the Single, times times.

Link copied to clipboard
fun <T> Single<T>.repeatUntil(predicate: (T) -> Boolean): Observable<T>

When the Single signals onSuccess, re-subscribes to the Single if the predicate function returns false.

Link copied to clipboard
fun <T> Single<T>.repeatWhen(handler: (attempt: Int, value: T) -> Maybe<*>): Observable<T>

When the Single signals onSuccess, re-subscribes to the Single when the Maybe returned by the handler function emits a value.

Link copied to clipboard
fun <T> Single<T>.retry(predicate: (attempt: Long, Throwable) -> Boolean = { _, _ -> true }): Single<T>

When the Single signals onError, re-subscribes to the Single if the predicate returns true.

fun <T> Single<T>.retry(times: Int): Single<T>

When the Single signals onError, re-subscribes to the Single, up to times times.

Link copied to clipboard
fun <T> Single<T>.retryWhen(handler: (Observable<Throwable>) -> Observable<*>): Single<T>

Returns a Single that automatically resubscribes to this Single if it signals onError and the Observable returned by the handler function emits a value for that specific Throwable.

Link copied to clipboard
inline fun <T> single(crossinline onSubscribe: (emitter: SingleEmitter<T>) -> Unit): Single<T>

Creates a Single with manual signalling via SingleEmitter.

Link copied to clipboard
fun <T> singleDefer(supplier: () -> Single<T>): Single<T>

Calls the supplier for each new observer and subscribes to the returned Single.

Link copied to clipboard
fun <T> singleFromFunction(func: () -> T): Single<T>

Returns a Single that emits the value returned by the func shared function.

Link copied to clipboard
fun <T> singleOf(value: T): Single<T>

Returns a Single that emits the specified value.

Link copied to clipboard
fun <T> singleOfError(error: Throwable): Single<T>

Returns a Single that signals the specified error via onError.

Link copied to clipboard

Returns a Single that never signals.

Link copied to clipboard
fun singleTimer(delay: Duration, scheduler: Scheduler): Single<Duration>

Signals onSuccess with delay value after the given delay.

Link copied to clipboard
inline fun <T> singleUnsafe(crossinline onSubscribe: (observer: SingleObserver<T>) -> Unit): Single<T>

⚠️ Advanced use only: creates an instance of Single without any safeguards by calling onSubscribe with a SingleObserver.

Link copied to clipboard
fun <T, R> singleUsing(resourceSupplier: () -> R, resourceCleanup: (resource: R) -> Unit, eager: Boolean = true, sourceSupplier: (resource: R) -> Single<T>): Single<T>

Returns a Single that for each subscription acquires a new resource via resourceSupplier, then calls sourceSupplier and subscribes to the returned upstream Single and disposes the resource via sourceSupplier when the upstream Single is finished (either terminated or disposed).

Link copied to clipboard
fun <T> Single<T>.subscribe(onSubscribe: (Disposable) -> Unit? = null, onError: (Throwable) -> Unit? = null, onSuccess: (T) -> Unit? = null): Disposable

Subscribes to the Single and provides event callbacks.

Link copied to clipboard
fun <T> Single<T>.subscribeOn(scheduler: Scheduler): Single<T>

Returns a Single that subscribes to the source Single on the specified Scheduler.

Link copied to clipboard
fun <T> Single<T>.timeout(timeout: Duration, scheduler: Scheduler, other: Single<T>? = null): Single<T>

Disposes the current Single if it does not signal within the timeout, and subscribes to other if provided.

Link copied to clipboard
fun <T> T.toSingle(): Single<T>

A convenience extensions function for singleOf.

Link copied to clipboard

A convenience extensions function for singleOfError.

Link copied to clipboard
Link copied to clipboard
fun <T, R> zip(vararg sources: Single<T>, mapper: (List<T>) -> R): Single<R>

Subscribes to all sourcess, accumulates all their values and emits a value returned by the mapper function.

fun <T1, T2, R> zip(source1: Single<T1>, source2: Single<T2>, mapper: (T1, T2) -> R): Single<R>
fun <T1, T2, T3, R> zip(source1: Single<T1>, source2: Single<T2>, source3: Single<T3>, mapper: (T1, T2, T3) -> R): Single<R>
fun <T1, T2, T3, T4, R> zip(source1: Single<T1>, source2: Single<T2>, source3: Single<T3>, source4: Single<T4>, mapper: (T1, T2, T3, T4) -> R): Single<R>
fun <T1, T2, T3, T4, T5, R> zip(source1: Single<T1>, source2: Single<T2>, source3: Single<T3>, source4: Single<T4>, source5: Single<T5>, mapper: (T1, T2, T3, T4, T5) -> R): Single<R>
fun <T1, T2, T3, T4, T5, T6, R> zip(source1: Single<T1>, source2: Single<T2>, source3: Single<T3>, source4: Single<T4>, source5: Single<T5>, source6: Single<T6>, mapper: (T1, T2, T3, T4, T5, T6) -> R): Single<R>
fun <T1, T2, T3, T4, T5, T6, T7, R> zip(source1: Single<T1>, source2: Single<T2>, source3: Single<T3>, source4: Single<T4>, source5: Single<T5>, source6: Single<T6>, source7: Single<T7>, mapper: (T1, T2, T3, T4, T5, T6, T7) -> R): Single<R>
fun <T1, T2, T3, T4, T5, T6, T7, T8, R> zip(source1: Single<T1>, source2: Single<T2>, source3: Single<T3>, source4: Single<T4>, source5: Single<T5>, source6: Single<T6>, source7: Single<T7>, source8: Single<T8>, mapper: (T1, T2, T3, T4, T5, T6, T7, T8) -> R): Single<R>
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> zip(source1: Single<T1>, source2: Single<T2>, source3: Single<T3>, source4: Single<T4>, source5: Single<T5>, source6: Single<T6>, source7: Single<T7>, source8: Single<T8>, source9: Single<T9>, mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9) -> R): Single<R>
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R> zip(source1: Single<T1>, source2: Single<T2>, source3: Single<T3>, source4: Single<T4>, source5: Single<T5>, source6: Single<T6>, source7: Single<T7>, source8: Single<T8>, source9: Single<T9>, source10: Single<T10>, mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) -> R): Single<R>

Subscribes to all source Singles, accumulates their values and emits a value returned by the mapper function.

Link copied to clipboard
fun <T, R> Iterable<Single<T>>.zip(mapper: (List<T>) -> R): Single<R>

Subscribes to all provided Singles, accumulates all their values and emits a value returned by the mapper function.

Link copied to clipboard
fun <T, R, I> Single<T>.zipWith(other: Single<R>, mapper: (T, R) -> I): Single<I>

Subscribes to both the current Single and the other, accumulates their values and emits a value returned by the mapper function.