Let's say I have a list that looks like
{A, B, C, D, E}
And I want to loop over this list, getting an increasing number of elements each time, so each iteration would look like:
Iteration 1: {A}
Iteration 2: {A, B}
Iteration 3: {A, B, C}
Iteration 4: {A, B, C, D}
Iteration 5: {A, B, C, D, E}
Currently I am accomplishing this with:
(1 to list.size).foreach( n => {
val elements = list.take(n)
// Do something with elements
})
But that feels messy. Is there a more 'scala' way of accomplishing this behavior?