Last

open class Last<T> : Disposable

Holder of a value that is computed in time.

Example usage is in automatic registering and unregistering of listeners.

Imagine a hypothetical API: - registerListener(Consumercallback) - unregisterListener(Consumer

Wrapping this type of API into a Lastis trivial:

Last.of(acceptor -> { Consumercallback = acceptor::onValue; acceptor.onDisposed(() -> api.unregisterListener(callback)); api.registerListener(callback); }, () -> "initial value");

Inheritors

Constructors

Link copied to clipboard
constructor(@NonNull holder: Consumer<Last.Acceptor<T>>, @Nullable defaultValue: T)

Types

Link copied to clipboard
interface Acceptor<T>

Functions

Link copied to clipboard
open fun close()
abstract fun close()
Link copied to clipboard
open fun dispose()
Dispose the resource.
Link copied to clipboard
@Contract(value = " -> new")
open fun disposed(): Disposable
Constructs and empty disposable that is already disposed.
Link copied to clipboard
@Contract(value = "_ -> new")
open fun fromRunnable(@NonNull run: Runnable): Disposable
Construct a Disposable by wrapping a Runnable that is executed exactly once when the Disposable is disposed.
Link copied to clipboard
open fun get(): T
Link copied to clipboard
open fun isDisposed(): Boolean
Returns true if this resource has been disposed.
Link copied to clipboard
open fun <R> map(mapper: (T) -> R): Last<R>
Link copied to clipboard
open fun observe(consumer: Consumer<T>): Disposable
Link copied to clipboard
@Contract(value = "_ -> new", pure = true)
open fun <T> of(@NonNull holder: Consumer<Last.Acceptor<T>>): Last<T>
@Contract(value = "_, _ -> new", pure = true)
open fun <T> of(@NonNull holder: Consumer<Last.Acceptor<T>>, @NonNull defaultValue: T): Last<T>