I have a mutablelist of items. One of the items pr...
# announcements
c
I have a mutablelist of items. One of the items properties is a date value. They are currently sorted by said date value. I want to insert separator items in-between the items that have different days. What's an idiomatic way to iterate through the mutablelist list and compare the current item and the next item to see if I should insert a separator?
k
However you’d have to deal with the edge-case of last index access yourself.
c
Thanks I'll take a look that!
👍 1
n
mapIndexed will not quite do it, I don't think, because the result list can have more items than the original one
probably want a combination of
windowed
and
fold
I think
c
Gotcha, thanks I'll take a look at windowed and fold (I haven't heard of windowed before).
c
zipWithNext
might also work
1
👍 2
n
yeah good call zipWithNext is basically windowed for n=2 but nicer