android-coroutines / nl.adaptivity.android.coroutines / Maybe

Maybe

sealed class Maybe<out T>

Types

CancellationCallback

interface CancellationCallback

Cancelled

object Cancelled : Maybe<Nothing>

Error

data class Error : Maybe<Nothing>

ErrorCallback

interface ErrorCallback

Ok

data class Ok<T> : Maybe<T>

SuccessCallback

interface SuccessCallback<in T>

Properties

isOk

val isOk: Boolean

Helper to determine whether the maybe has a value.

Functions

flatMap

abstract fun <R> flatMap(function: (T) -> R): R?fun flatMap(): T?

Flatmap the identity function. Basically this gives the value for Ok, null when cancelled or throws the exception for an error state.

map

fun <R> map(function: (T) -> R): Maybe<R>

Create a new maybe with the function applied to the data (on Ok values only).

onCancelled

fun onCancelled(function: CancellationCallback): Unit?
fun <R> onCancelled(function: Cancelled.() -> R): R?

onError

fun onError(function: ErrorCallback): Unit?
fun <R> onError(function: Error.(Exception) -> R): R?

onOk

fun onOk(function: SuccessCallback<T>): Unit?
fun <R> onOk(function: Ok<*>.(T) -> R): R?

select

abstract fun <T> select(ok: T, cancelled: T, error: T): T

Companion Object Functions

cancelled

fun <T> cancelled(): Maybe<T>

error

fun <T> error(e: Exception): Maybe<T>

Inheritors

Cancelled

object Cancelled : Maybe<Nothing>

Error

data class Error : Maybe<Nothing>

Ok

data class Ok<T> : Maybe<T>