rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.69k stars 303 forks source link

Add `circular_slice()` #829

Closed nmay231 closed 8 months ago

nmay231 commented 8 months ago

I'm willing to implement if approved. I didn't see a similar issue or implementation. I'll add more details once I get back from doing some chores.

let arr = vec![1, 2, 3, 4, 5, 6];

itertools::assert_equal(arr.iter().circular_slice(1..4), &[2, 3, 4]);
itertools::assert_equal(arr.iter().circular_slice(4..1), &[5, 6, 1]);
nmay231 commented 8 months ago

Actually, I thought this would require heap allocations, but this could probably be implemented in core if they accept it. Closing for now.