Idiomatic way of splitting iterator of Result into two iterators (Ok, Err)

It is acceptable for an Iterator to resume iteration after returning None. It would be valid for an implementation of let (ok_iter, err_iter) = result_iter.split_ok_err(); to return two iterators that yield None until the next value in the source iterator matches their expected Result variant. That implementation would only require enough memory to store a single Result<T, E>, by using .peek() on the source iterator for example.

Here's a possible implementation.

1 Like