I want to execute a bunch of functions that all return results. I want to return the first error that occurred in the executions, but I always want to execute all functions, even if an error occurred somewhere. I initially thought of using
but find() is short-circuiting, meaning it won't continue executing after finding the first error. What is the best way to implement my requirements? Is there some non-shortcircuiting version of find()
Does it have to be the first error or can it be any error? I'm asking because iterators try to be short-circuiting whenever possible. So find, collect and filter(...).next() are all short-circuiting and off the table. What isn't is filter(Result::is_err).last(), so if you are comfortable with returning the last error, you could do something like:
No, because you have to execute them to know that they are Oks. last can't short circuit; it has to keep calling next on the inner iterator until it returns None.
Result::and selects either an error from the result accumulator (the first error seen) or the result from the execute function (either Ok or Err).
Because the argument to and is executed before and sees that result is already an Err, f.execute() will be run on each item, even when result is an Err.