How to concatenate separately declared modifiers?

val modifierA = Modifier.size(100.dp)
val modifierB = Modifier.background(Color.Red)

How do you create a modifierC that is the concatenation of A and B?

I tried using .apply and .also, but to no avail.

Answer

You can use the composed function:

Declare a just-in-time composition of a Modifier that will be composed for each element it modifies

Something like:

Box(modifierA.composed{ modifierB })

or

val modifierC = modifierA.composed{ modifierB }
Box(modifierC) {}

enter image description here