I think fold is a good name, meaning that it is worth trying to generalize the existing fold to enable the short-circuit behavior.
Right. I think this is the explanation that should be added to the RFC. Expanding on it, there are many possible functions with the signature (Result<Acc, E>, Self::Item) -> Result<Acc, E>. Only one of them is the short-circuiting behavior. Thus, automatically specializing fold() for such functions to do short-circuiting would prevent any other kinds of folds with the same signature, and would be generally surprising.
Yes, that’s good. But like I said above, it would be better to find a way to generalize fold() so that it can do the short-circuiting, without defining a new fold_ok().
In particular, we want to fold using a function (Acc, Self::Item) -> Result<Acc, E> such that the folding is terminated as soon as the function returns Err(e). We already have a fold function that takes a function with signature (Acc, Self::Item) -> Acc. Thus, I’m suggesting we define a combinator that converts a function of type (Acc, Self::Item) -> Result<Acc, E> into a function-like object of type (Result<Acc, E>, Self::Item) -> Result<Acc, E>. Let’s say the function is named short_circuit and the function-like object it returns is of type ShortCircuit.
Then, the existing fold() could be specialized for ShortCircuit to end the fold early when the ShortCircuit returns Err(e).
Note that this may not be possible with the current type system of Rust. But, I’d say that it seems worthwhile to improve the type system to make this possible (if necessary) rather than adding a new fold_ok function.
Edit: Even better, if we define such a short_curcuit function that returns such a ShortCircuit function-like object, then the optimizer should often (in theory) be able optimize the function to do short-circuiting as long as the folding function is side-effect-free(-ish), AFAICT.