what's the rust thing for turning a Vec<Result> (or an Iterator<Item = Result>) into a Result<Vec>
-
Show this thread
-
getting Vec<Result> from the Iterator is just collect(), but I'm not sure about Result<Vec>
4 replies 0 retweets 3 likesShow this thread -
so thanks to
@bodil it turns out this is also just a call to collect(), you just say you want a Result<Vec<_>, _>, b/c Result<V, E> implements FromIterator<Result<A, E>> where V: FromIterator<A>1 reply 0 retweets 9 likesShow this thread -
this is honestly still kind of magical to me even after writing thousands of words about it https://blog.jcoglan.com/2019/04/22/generic-returns-in-rust/ …
6 replies 0 retweets 11 likesShow this thread -
so, it occurs to me that this is a gap in the rust docs -- trait implementations don't typically get docs shown, e.g. https://doc.rust-lang.org/std/result/enum.Result.html#impl-FromIterator%3CResult%3CA%2C%20E%3E%3E …
1 reply 0 retweets 2 likesShow this thread -
the implementation of <Result<V, E> as FromIterator<Result<A, E>>::from_iter is far from obvious and has behaviour that's only apparent from reading the source
1 reply 0 retweets 1 likeShow this thread -
it has behaviour somewhat like Promise.all in JS: if any items in the iterator are Err, you get an Err, otherwise you get an Ok with the desired collection type
2 replies 0 retweets 1 likeShow this thread -
this it not at all unreasonable behaviour, it's just not obvious, and I might expect different behaviour for other monads e.g. I think it would be reasonable for FromIterator<Option<A>> for Option<V> to return a V containing only the Some items
2 replies 0 retweets 3 likesShow this thread -
i.e. the same as filter_map? but it doesn't, it behaves like Result: if any items are None, you get None, otherwise you get Some(V)
1 reply 0 retweets 0 likesShow this thread -
and that's also a completely reasonable semantics it's just... not obvious, and the docs should expose the comments that are in the source
1 reply 0 retweets 3 likesShow this thread
FWIW the docs seem pretty comprehensive to mepic.twitter.com/xypUcYyrbn
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.