You can discard the first element before undoing it:
for(thing <- things.drop(1).reverse) {
}
For lists, the drop(1)same as tailif the list is not empty:
for(thing <- things.tail.reverse) {
}
or you can do the opposite first and use dropRight:
for(thing <- things.reverse.dropRight(1)) {
}
You can also use initif the list is not empty:
for(thing <- things.reverse.init) {
}
source
share