[Solved] `transpose` for iterators?

I’ve just noticed that we now have https://doc.rust-lang.org/std/result/enum.Result.html?search=transpose for Result<Option<>> <-> Option<Result<>> conversion. Very nice!

Have anyone consider adding it to iterators as well? I was maintaining a small crate implementing exactly this: https://github.com/dpc/insideout/blob/564614969e7c6400d34e8d4a03882e2549255aad/src/lib.rs#L59 and I would be happy to retire it.

This seems just like

let iterator : impl Iterator<Item = Result<Option<T>, E>>;

iterator.map(Result::transpose)

// or

let iterator : impl Iterator<Item = Option<Result<T, E>>>;

iterator.map(Option::transpose)
2 Likes

Duh. Thank you!:smiley:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.