https://kotlinlang.org logo
#compose
Title
# compose
c

chanjungskim

03/28/2023, 3:29 AM
What is 'foldIn' and 'foldOut' of Modifier??
l

Loney Chou

03/28/2023, 3:40 AM
It's like
Iterable.fold
but Modifier version. When you construct a Modifier chain using
then
or whatever its wrapper like
Modifier.size
, the element at the front is called
outer
, while at the back is
inner
. So
foldIn
iterates from the first to the last, the other one backwards.
Copy code
Modifier
    .size
    .padding
    .background
    .foldIn(Unit) { _, element ->
        println(element::class.simpleName)
    }
will print
Copy code
SizeElement
PaddingElement
BackgroundElement
c

chanjungskim

03/28/2023, 8:26 AM
When do you use foldIn and foldOut?
l

Loney Chou

03/28/2023, 8:34 AM
Probably never. It's like something that is used for internal stuff.
d

dewildte

03/28/2023, 7:59 PM
286 Views