letIf

inline fun <T> T.letIf(predicate: Boolean, transform: (T) -> T): T(source)

Conditionally applies the provided transform function to the receiver object if the predicate is true, then returns the result of that transform. If the predicate is false, the receiver object itself is returned.

Return

The result of the transform function if the predicate is true, or the receiver object itself otherwise.

Parameters

predicate

The predicate to determine whether to apply the transform function.

transform

The transform function to apply to the receiver object.