itertools icon indicating copy to clipboard operation
itertools copied to clipboard

TupleCollect for N = 0

Open ivan770 opened this issue 4 years ago • 2 comments

Currently, it's impossible to use next_tuple and similar tuple methods for unit type, even though such an impl could just return empty tuple on each call, without advancing inner iterator.

ivan770 avatar Sep 21 '21 11:09 ivan770

Can you say more about why this would be useful to you? I feel like I'd most often want the compiler error here, because if I'm using next_tuple I'm expecting to advance the iterator. Accidentally getting an infinite iterator of units -- which I can't think of why I'd ever want as an adapter, and iter::repeat(()) exists if needed -- feels like it'd be easily error-prone.

scottmcm avatar Sep 21 '21 17:09 scottmcm

Can you say more about why this would be useful to you? I feel like I'd most often want the compiler error here, because if I'm using next_tuple I'm expecting to advance the iterator. Accidentally getting an infinite iterator of units -- which I can't think of why I'd ever want as an adapter, and iter::repeat(()) exists if needed -- feels like it'd be easily error-prone.

At first I wanted to use unit tuples as a placeholder for "Callable that doesn't require any args" in API like this: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=eea1cf14d62513501165abca7fcf11e0. However, the whole idea was wrong and eventually API got changed, since there is also a problem with specifying the item type here: https://github.com/rust-itertools/itertools/blob/master/src/tuple_impl.rs#L271. Quite unsure now if it's even implementable without something like never-type.

ivan770 avatar Sep 21 '21 18:09 ivan770