ObjectUtils<T> extension

Kotlin-style scope function extensions on any Object.

These are inspired by Kotlin's let, also, takeIf, and takeUnless and are useful for chaining operations without intermediate variables.

on
  • T

Methods

also(void block(T)) → T

Available on T, provided by the ObjectUtils extension

Calls block with this value for a side effect, then returns this value.
let<R>(R block(T)) → R

Available on T, provided by the ObjectUtils extension

Calls block with this value and returns the result.
takeIf(bool predicate(T)) → T?

Available on T, provided by the ObjectUtils extension

Returns this value if predicate is true, otherwise null.
takeUnless(bool predicate(T)) → T?

Available on T, provided by the ObjectUtils extension

Returns this value if predicate is false, otherwise null.