what part? we need a function that does 2 things
1. filter out deleted messages
2. provide the next message, for the UI to use
I'm curious what you'd do differently
> Or use a normal loop.
i was waiting for someone to say that
you don't have a function that needs to do two things, you have two distinct problems to solve and a stack of code that hides bugs and performance issues
Why not return each undeleted item with their next companion deleted or not?
The exception raised when the last item is not deleted is a feature, not a bug.
No specs, no bug.