takeUnless

inline fun <T> T.takeUnless(predicate: (T) -> Boolean): T?(source)

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

The predicate receives the original value, including null, and runs once. Its exceptions propagate and the inline predicate supports non-local returns. A null result can mean either rejection or acceptance of a null receiver.

Receiver

value to test.

Return

the original receiver when the predicate is false, or null when it is true.

Parameters

predicate

test that returns true to reject the value.

Type Parameters

T

type of the receiver, which may be nullable.

See also