rust-itertools / itertools

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

Implement ExactSizeIterator for CircularTupleWindows #660

Closed xamgore closed 1 year ago

xamgore commented 1 year ago

.circular_tuple_windows() will produce the same amount of elements as the upstream iterator, so I believe the implementation should be pretty simple.

Speaking about the practical example, I want to convert a vector of 2D points to pairs of normalized vectors.

  let vecs = shape
    .into_iter()
    .circular_tuple_windows::<(_, _)>()
    .map(|((x1, y1), (x2, y2)): (Point, Point)| (x2 - x1, y2 - y1) as Point)
    .circular_tuple_windows(); //  trait `ExactSizeIterator` is not satisfied
xamgore commented 10 months ago

@Philippe-Cholet what an excellent work, thank you so much! ❤️

Philippe-Cholet commented 10 months ago

@xamgore You are welcome. Thanks for pointing that out.