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

try_fold_while #830

Open mightyiam opened 8 months ago

mightyiam commented 8 months ago

I found myself wanting a try_fold_while... Since there fold_while is not in std, I don't suppose it's the right time to RFC try_fold_while in std. So, would it be accepted here?

I haven't gotten into any detail, but I imagine it to be a straightforward combination of try_fold and fold_while.

Philippe-Cholet commented 8 months ago

The Try trait behind try_fold is unstable so we can't specialize them. And I think try_ methods should use Try. We only have one try_ method: try_collect which is in conflict with the unstable std one. An alternative would be fold_while_ok (we have a bunch of _ok methods, I don't know if we want more), or use our process_results (it_res.process_results(|it| it.fold_while(...))) but it doesn't specialize try_fold either so I guess the performance might be unsatisfying.

mightyiam commented 8 months ago

I suppose we wait, then.