I’ve found the
PartialIteration objects to be really helpful, and I’ve wished I could use them more easily in other loops.
My proposal is two-part: extract PartialIteration out of ActionView and into ActiveSupport as a more generic Iteration object (implementation can stay the same, just a new less View-specific name).
And then a core extension to
Enumerator like this:
def with_iteration iteration = ActionView::PartialIteration.new(size) with_object(iteration) do |*args| yield *args iteration.iterate! end end
And then for an example use:
- 5.times.with_iteration do |_, iteration| - unless iteration.last? .timeline-bar .timeline-element - # ...
I would be happy to put together a PR, but before I went through the trouble I thought I would see if there was any interest.