question: how would you do something specific only...
# getting-started
x
question: how would you do something specific only on last index while doing a collection.map{ }?
p
use
mapIndexed
and check if the first parameter is the collection's size...if the collection is actually sized
☝️ 2
x
awesome, thank you!
c
You can do something like:
Copy code
yourList
  .mapIndexed { (i, it) ->
    if (i == yourList.lastIndex) foo()
    else bar()
  }
👍 1