Maybe

interface Maybe<out T> : Source<MaybeObserver<T>>

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

There are a number of factory functions available, their names all begin with maybe*(...).

See Source and MaybeCallbacks for more information.

Inheritors

Functions

Link copied to clipboard

Returns a Completable which signals onComplete when this Maybe signals either onSuccess or onComplete.

Link copied to clipboard

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

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

Converts this Maybe into a Single, which signals either a success value (if this Maybe succeeds) or the defaultValue (if this Maybe completes).

fun <T> Maybe<T>.asSingle(defaultValueSupplier: () -> T): Single<T>

Converts this Maybe into a Single, which signals either a success value (if this Maybe succeeds) or a value returned by defaultValueSupplier (if this Maybe completes).

Link copied to clipboard
fun <T> Maybe<T>.asSingleOrError(errorSupplier: () -> Throwable): Single<T>

Converts this Maybe into a Single, which signals a success value via onSuccess (if this Maybe succeeds) or a Throwable returned by errorSupplier via onError (if this Maybe completes).

fun <T> Maybe<T>.asSingleOrError(error: Throwable = NoSuchElementException()): Single<T>

Converts this Maybe into a Single, which signals a success value via onSuccess (if this Maybe succeeds) or error via onError (if this Maybe completes).

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

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

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

Delays onSuccess and onComplete signals from the current Maybe 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> Maybe<T>.delaySubscription(delay: Duration, scheduler: Scheduler): Maybe<T>

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

Link copied to clipboard
fun <T> Maybe<T>.doOnAfterComplete(action: () -> Unit): Maybe<T>

Calls the action when the Maybe signals onComplete. The action is called after the observer is called.

Link copied to clipboard
fun <T> Maybe<T>.doOnAfterDispose(action: () -> Unit): Maybe<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> Maybe<T>.doOnAfterError(consumer: (Throwable) -> Unit): Maybe<T>

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

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

Calls the action when one of the following events occur:

Link copied to clipboard
fun <T> Maybe<T>.doOnAfterSubscribe(action: (Disposable) -> Unit): Maybe<T>

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> Maybe<T>.doOnAfterSuccess(consumer: (T) -> Unit): Maybe<T>

Calls the consumer with the emitted value when the Maybe signals onSuccess. The consumer is called after the observer is called.

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

Calls the action when the Maybe signals a terminal event: onSuccess, onComplete or onError. The action is called after the observer is called.

Link copied to clipboard
fun <T> Maybe<T>.doOnBeforeComplete(action: () -> Unit): Maybe<T>

Calls the action with the emitted value when the Maybe signals onComplete. The action is called before the observer is called.

Link copied to clipboard
fun <T> Maybe<T>.doOnBeforeDispose(action: () -> Unit): Maybe<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> Maybe<T>.doOnBeforeError(consumer: (Throwable) -> Unit): Maybe<T>

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

Link copied to clipboard
fun <T> Maybe<T>.doOnBeforeFinally(action: () -> Unit): Maybe<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> Maybe<T>.doOnBeforeSuccess(consumer: (T) -> Unit): Maybe<T>

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

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

Calls the action when the Maybe signals a terminal event: onSuccess, onComplete or onError. The action is called before the observer is called.

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

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

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

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

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

Calls the mapper with the value emitted by the Maybe 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.

Link copied to clipboard

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

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

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

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

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

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

Calls the mapper with the value emitted by the Maybe 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
fun <T, R> Maybe<T>.flatMapSingle(mapper: (T) -> Single<R>): Maybe<R>

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

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

Calls the mapper with the value emitted by the Maybe 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
@JvmName(name = "flattenObservable")
fun <T> Maybe<Observable<T>>.flatten(): Observable<T>

This is just a shortcut for Maybe.flatMapObservable.

When the Maybe 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> Maybe<T>.map(mapper: (T) -> R): Maybe<R>

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

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

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

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

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

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

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

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

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

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

Signals all events of the Maybe on the specified Scheduler.

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

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

Link copied to clipboard

Returns a Maybe which completes when this Maybe signals onError.

Link copied to clipboard
fun <T> Maybe<T>.onErrorResumeNext(next: Maybe<T>): Maybe<T>

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

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

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

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

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

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

When the Maybe signals onError, emits the value.

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

When the Maybe signals onSuccess or onComplete, re-subscribes to the Maybe, times times.

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

When the Maybe signals onSuccess or onComplete, re-subscribes to the Maybe if the predicate function returns false.

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

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

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

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

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

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

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

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

Link copied to clipboard
abstract fun subscribe(observer: MaybeObserver<T>)

Subscribes the specified Observer to this Source

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

Subscribes to the Maybe and provides event callbacks.

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

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

Link copied to clipboard
fun <T> Maybe<T>.switchIfEmpty(other: Maybe<T>): Maybe<T>

Returns a Maybe that first subscribes to this Maybe and signals its events, unless this Maybe signals onComplete. If this Maybe signals onComplete, then subscribes to the other and signals its events.

fun <T> Maybe<T>.switchIfEmpty(other: Single<T>): Single<T>

Returns a Maybe that first subscribes to this Maybe and signals its events, unless this Maybe signals onComplete. If this Maybe signals onComplete, then subscribes to the other and signals its events.

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

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

Link copied to clipboard
fun <T : Any> Maybe<T>.wrap(): MaybeWrapper<T>
Link copied to clipboard
fun <T, R, I> Maybe<T>.zipWith(other: Maybe<R>, mapper: (T, R) -> I): Maybe<I>