transformIf
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) }Content copied to clipboard
Return
the transformed value, or the receiver unchanged.
Parameters
condition
whether to apply transform.
transform
mapping from the current value to its replacement.