Result

abstract class Result<T, E>

A result class models the possibility of a success or failure event occurring.

A success is modeled by the Ok subtype, while an error is modeled by the Err subtype. While neither type is different (they are both wrappers around one value), the "left" type (T) represents a success, while the "right" (E) represents failure.

This is similar to the Result type in Rust and Scala.

Do NOT use this class to model anything but success and failure. For example, don't use it to model a method that could return two possible types if they're both successful outcomes. The semantics would be wrong.

Ok and Err are the only two possible subtypes.

For Ok, a value will be present of type T, retrievable via .getOrNull or the other get methods.

For Err, a value will be present of type E, retrievable via .getErr

Parameters

the type of the possible "err" value

Types

Link copied to clipboard
class Err<T, E>(val value: E) : Result<T, E>
Link copied to clipboard
class Ok<T, E>(val value: T) : Result<T, E>

Functions

Link copied to clipboard
fun getOrElse(defaultValue: T): T?
Link copied to clipboard
fun getOrNull(): T?
Link copied to clipboard
fun getOrThrow(toThrow: RuntimeException): T?

Properties

Link copied to clipboard
val err: E?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val result: T

Inheritors

Link copied to clipboard
Link copied to clipboard