Draft RFC: fold_ok
is composable internal iteration
This RFC has several motivations, that were developed in the order listed(!)
- A common base for searching and folding methods (for internal iteration)
- A common base for reversible iterator methods; i.e having
fold_ok
and its correspondingrfold_ok
brings symmetry and equal power to the reversed iterators. - A useful iterator method
Summary
Add the iterator method fold_ok that exends fold to be fallible and short-cirtuiting. fold_ok generalizes the existing methods all, any, find, position and fold, and will be their new common base; iterators can provide one specific traversal implementation for all of them. Iterators can additionally implement rfold_ok to have the same search and fold methods improved through their reversed iterator as well.
cc @Veedrac and thank you for the feedback so far! The draft has an example of the take adaptor and why fold_ok
can be general in the error type of the result. This made it really click into place for me, the Result
version is versatile and clearly superior.
Previous discussion on the same topic: