Mark
04/09/2023, 4:01 AMfor (index in 0 until itemCount) {
2️⃣ repeat(itemCount) { index ->
asdf asdf
04/09/2023, 4:32 AMJoffrey
04/09/2023, 7:07 AMrepeat
if you want to repeat something multiple times. Use forEach
or forEachIndexed
if you want to iterate a collection. I rarely ever use explicit for
loopsMark
04/09/2023, 9:06 AMindex
refers to an item index in a list (but we do not have direct access to that list, otherwise we would just use forEachIndexed
)Joffrey
04/09/2023, 9:21 AMMark
04/09/2023, 9:36 AMgetItemId
in RecyclerView.Adapter
In my particular case (not using that exact function) I have:
for (position in 0 until itemCount) {
val item = itemAtPosition(position)
if (item is Foo) {
notifyItemChanged(position)
}
}
ephemient
04/11/2023, 6:51 AMfor (index in list.indices) {
for ((index, elem) in list.withIndex()) {
works better in context, of course)Mark
04/12/2023, 5:10 AMJan
04/12/2023, 7:24 PMephemient
04/12/2023, 7:26 PMRandomAccess
lists which aren't being mutated, which should be most lists, but it's hard to guarantee unless you are in control of the data (and Compose only uses those helpers on its own data)Jan
04/12/2023, 8:36 PMMarcin Wisniowski
04/17/2023, 10:06 AMcontinue
in your loop body, you can't use repeat
.