https://kotlinlang.org logo
#announcements
Title
# announcements
w

william

10/30/2019, 3:30 AM
is there a more kotlin idiomatic way of doing this?
Copy code
for (i in 0..fooCount) {
            foos.add(bar.getFoo(i))
        }
j

jw

10/30/2019, 3:30 AM
That is fine. If you're golfing code, you can do things like
val foos = (0..fooCount).map(bar::getFoo)
w

william

10/30/2019, 3:31 AM
ok thanks, sometimes i'm not completely sure whether to cross the line and do things like that vs keeping it simpler
k

Krotick

10/30/2019, 4:08 AM
fooCount must be coming from somewhere ...
Copy code
collectionWhereFooCountCameFrom.forEach {         foos.add(collectionElement)
}
w

william

10/31/2019, 11:35 PM
@Krotick its not iterable so i can't do that
k

Krotick

11/04/2019, 4:28 PM
it makes total sense then!
3 Views