android-components / mozilla.components.support.base.observer / Consumable

Consumable

class Consumable<T> (source)

A generic wrapper for values that can get consumed.

Parameters

value - The value to be wrapped.

onConsume - A callback that gets invoked if the wrapped value gets consumed.

Functions

Name Summary
consume fun consume(consumer: (value: T) -> Boolean): Boolean
Invokes the given lambda and marks the value as consumed if the lambda returns true.
consumeBy fun consumeBy(consumers: List<(T) -> Boolean>): Boolean
Invokes the given list of lambdas and marks the value as consumed if at least one lambda returns true.
isConsumed fun isConsumed(): Boolean
Returns whether the value was consumed.
onConsume fun onConsume(listener: ConsumableListener): Unit
Adds a listener to be invoked when this Consumable is consumed.
peek fun peek(): T?
Returns the value of this Consumable without consuming it.

Companion Object Functions

Name Summary
empty fun <T> empty(): Consumable<T>
Returns an empty Consumable with not value as if it was consumed already.
from fun <T> from(value: T, onConsume: () -> Unit = null): Consumable<T>
Creates a new Consumable wrapping the given value.
stream fun <T> stream(vararg values: T): ConsumableStream<T>
Creates a new Consumable stream for the provided values.