Package-level declarations

Types

Link copied to clipboard
class WeakLazy<T : Any>(initializer: () -> T)

A lazily computed value cached through a WeakRef, so the cached instance can be garbage collected and recomputed later.

Functions

Link copied to clipboard
inline fun <T> T.alsoIf(condition: Boolean, block: (T) -> Unit): T

Passes this receiver to block when condition is true and returns the receiver.

Link copied to clipboard
inline fun <T> T.applyIf(condition: Boolean, block: T.() -> Unit): T

Runs block on this receiver when condition is true and returns the receiver.

Link copied to clipboard
inline fun <T> T.applyUnless(condition: Boolean, block: T.() -> Unit): T

Runs block on this receiver when condition is false and returns the receiver.

Link copied to clipboard

Closes this resource, swallowing any Exception thrown by AutoCloseable.close.

Link copied to clipboard
fun <A, B, C> Triple<A, B, C>.dropFirst(): Pair<B, C>

Returns a Pair of the second and third components, discarding the first.

Link copied to clipboard
fun <A, B, C> Triple<A, B, C>.dropSecond(): Pair<A, C>

Returns a Pair of the first and third components, discarding the second.

Link copied to clipboard
fun <A, B, C> Triple<A, B, C>.dropThird(): Pair<A, B>

Returns a Pair of the first and second components, discarding the third.

Link copied to clipboard
inline fun <T, R> Result<T>.flatMap(transform: (T) -> Result<R>): Result<R>

Returns the result of transform applied to the encapsulated value, or the original failure.

Link copied to clipboard

Returns the inner Result, collapsing one level of nesting.

Link copied to clipboard
inline fun <T> Result<T>.isFailureAnd(predicate: (Throwable) -> Boolean): Boolean

Returns true when this Result is a failure whose exception satisfies predicate.

Link copied to clipboard
inline fun <T> Result<T>.isSuccessAnd(predicate: (T) -> Boolean): Boolean

Returns true when this Result is a success whose value satisfies predicate.

Link copied to clipboard
inline fun <A, B, C, D> Pair<A, B>.mapBoth(transformFirst: (A) -> C, transformSecond: (B) -> D): Pair<C, D>

Returns a new Pair with both components transformed independently.

Link copied to clipboard
inline fun <T> Result<T>.mapFailure(transform: (Throwable) -> Throwable): Result<T>

Returns a Result whose failure exception is replaced by the result of transform, or the original success.

Link copied to clipboard
inline fun <A, B, R> Pair<A, B>.mapFirst(transform: (A) -> R): Pair<R, B>

Returns a new Pair whose first component is the result of transform applied to the current first component.

inline fun <A, B, C, R> Triple<A, B, C>.mapFirst(transform: (A) -> R): Triple<R, B, C>

Returns a new Triple whose first component is the result of transform applied to the current first component.

Link copied to clipboard
inline fun <A, B, R> Pair<A, B>.mapSecond(transform: (B) -> R): Pair<A, R>

Returns a new Pair whose second component is the result of transform applied to the current second component.

inline fun <A, B, C, R> Triple<A, B, C>.mapSecond(transform: (B) -> R): Triple<A, R, C>

Returns a new Triple whose second component is the result of transform applied to the current second component.

Link copied to clipboard
inline fun <A, B, C, R> Triple<A, B, C>.mapThird(transform: (C) -> R): Triple<A, B, R>

Returns a new Triple whose third component is the result of transform applied to the current third component.

Link copied to clipboard

Returns this value, or false when this value is null.

Link copied to clipboard

Returns this value, or true when this value is null.

Link copied to clipboard
fun <A, B> Pair<A, B>.swapped(): Pair<B, A>

Returns a new Pair with the components exchanged.

Link copied to clipboard

Returns 1 when this value is true and 0 when it is false.

Link copied to clipboard
fun <A, B, C> Pair<A, B>.toTriple(third: C): Triple<A, B, C>

Returns a Triple of this pair's components followed by third.

Link copied to clipboard
inline fun <T> T.transformIf(condition: Boolean, transform: (T) -> T): T

Returns the result of transform applied to this value when condition is true, otherwise this value.

Link copied to clipboard
inline fun <T> tryOrDefault(default: T, block: () -> T): T

Runs block and returns its value, or default when it throws an Exception.

Link copied to clipboard
inline fun <T> tryOrElse(fallback: (Exception) -> T, block: () -> T): T

Runs block and returns its value, or the value of fallback applied to the thrown Exception.

Link copied to clipboard
inline fun <T> tryOrNull(block: () -> T): T?

Runs block and returns its value, or null when it throws an Exception.

Link copied to clipboard
inline fun <T> useAll(vararg resources: AutoCloseable, block: () -> T): T

Runs block and then closes every resource in resources in reverse order.

Link copied to clipboard
inline fun <T> Iterable<AutoCloseable>.useAll(block: () -> T): T

Runs block and then closes every resource in this collection in reverse iteration order.

Link copied to clipboard
fun <T : Any> weakLazy(initializer: () -> T): WeakLazy<T>

Returns a WeakLazy that computes its value with initializer.

Link copied to clipboard
inline fun <A, B, R> Result<A>.zip(other: Result<B>, combine: (A, B) -> R): Result<R>

Combines this Result with other via combine, failing when either is a failure.

inline fun <A, B, C, R> Result<A>.zip(second: Result<B>, third: Result<C>, combine: (A, B, C) -> R): Result<R>

Combines this Result with second and third via combine, failing when any is a failure.