transform

Transforms a MutablePreviewLabField to work with a different value type.

This extension function creates a TransformField that allows you to work with a transformed representation of the original field's value while keeping the original field's UI and behavior.

Usage

val stringField: StringField = StringField("number", "42")
val intField: TransformField<String, Int> = stringField.transform(
transform = { it.toIntOrNull() ?: 0 },
reverse = { it.toString() }
)

Return

A TransformField that presents the transformed value type.

Parameters

transform

Function to convert from base value to transformed value.

reverse

Function to convert from transformed value back to base value.

label

Label for the transformed field. Defaults to the original field's label.

initialValue

Initial value for the transformed field. Defaults to transforming the original field's current value.