Package-level declarations

Types

Link copied to clipboard
interface Maybe<out T> : Source<MaybeObserver<T>>

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

Link copied to clipboard

Callbacks for Maybe source See Maybe, SuccessCallback and CompletableCallbacks for more information.

Link copied to clipboard

Represents an emitter for Maybe source. See Emitter and MaybeCallbacks for more information.

Link copied to clipboard

Represents an Observer of Maybe source. See Observer and MaybeCallbacks for more information.

Link copied to clipboard
open class MaybeWrapper<out T : Any>(inner: Maybe<T>) : Maybe<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: Maybe<T>): Maybe<T>

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

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

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

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> concat(vararg sources: Maybe<T>): Observable<T>

Concatenates multiple Maybe sources one by one into an Observable.

Link copied to clipboard

Concatenates multiple Maybe sources one by one into an Observable.

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
inline fun <T> maybe(crossinline onSubscribe: (emitter: MaybeEmitter<T>) -> Unit): Maybe<T>

Creates a Maybe with manual signalling via MaybeEmitter.

Link copied to clipboard
fun <T> maybeDefer(supplier: () -> Maybe<T>): Maybe<T>

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

Link copied to clipboard
fun <T> maybeFromFunction(func: () -> T): Maybe<T>

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

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

Returns a Maybe that emits the specified value. The value is emitted even if it is null.

Link copied to clipboard
fun <T> maybeOfEmpty(): Maybe<T>

Returns a Maybe that signals onComplete.

Link copied to clipboard
fun <T> maybeOfError(error: Throwable): Maybe<T>

Returns a Maybe that signals the specified error via onError.

Link copied to clipboard
fun <T> maybeOfNever(): Maybe<T>

Returns a Maybe that never signals.

Link copied to clipboard
fun <T : Any> maybeOfNotNull(value: T?): Maybe<T>

Returns a Maybe that emits the provided value if it is not null, otherwise completes.

Link copied to clipboard
fun maybeTimer(delay: Duration, scheduler: Scheduler): Maybe<Duration>

Signals onSuccess with delay value after the given delay.

Link copied to clipboard
inline fun <T> maybeUnsafe(crossinline onSubscribe: (observer: MaybeObserver<T>) -> Unit): Maybe<T>

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

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

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

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

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

Link copied to clipboard

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

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
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> T.toMaybe(): Maybe<T>

A convenience extensions function for maybeOf.

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

A convenience extensions function for maybeOfNotNull.

Link copied to clipboard

A convenience extensions function for maybeOfError.

Link copied to clipboard
fun <T : Any> Maybe<T>.wrap(): MaybeWrapper<T>
Link copied to clipboard
fun <T, R> zip(vararg sources: Maybe<T>, mapper: (List<T>) -> R): Maybe<R>

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

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

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

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

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

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