sub cycle { my ($repeat, $items, $index) = @_; return sub { $items->[ int ($index++ / $repeat) % @$items ]; } }