transformIf

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.

Unlike applyIf, the block produces a replacement value instead of mutating the receiver, so it also works with immutable types.

val label = name.transformIf(truncate) { it.take(8) }

Return

the transformed value, or the receiver unchanged.

Parameters

condition

whether to apply transform.

transform

mapping from the current value to its replacement.