Various inconsistencies around sync/async in TryStreamExt
and StreamExt
#2518
Labels
Milestone
TryStreamExt
and StreamExt
#2518
This is related to #2470 but has some complexity because it's Streams, not Futures. It also touches on the same area as #2237 but has more reasoning.
For
StreamExt
, we want every combinator to somehow exist in two forms -map
andthen
are a good example of the two forms - where one form is sync likemap
(FnMut(Self::Item) -> T
) and the other is async likethen
(FnMut(Self::Item) -> impl Future
). Where we only have one form, we can use anasync { ... }
block to enable us to use the async form for a sync call.Looking at the documentation for
StreamExt
, it's onlymap
andthen
that provide this duality -futures
lacks similar duality forfilter
,filter_map
,flat_map
,fold
,any
,all
,scan
,skip_while
,take_while
,take_until
,for_each
andfor_each_concurrent
. I think it would be worth considering whether we want to have the dual sync/async forms for every one of these, whethermap
andthen
are different because they are special, or whether we should consider losingmap
and just havingthen
.TryStreamExt
is more complicated. As well as the sync/async duality, we also have three possible input types (Self::Item
,Self::Item::Ok
andSelf::Item::Err
) and three possible return types (Result<T, E>
,T
andE
). This leads to us needing 18 variants to cover all the options for each of the 12 combinators thatStreamExt
provides (countingfor_each
as a special case offor_each_concurrent
. I don't think that providing 216 combinators blindly is a good idea, which leaves us wanting to think about what subset of the 216 is needed.Talking to co-workers, two that are most often wanted are a
then_ok
to be the async dual ofmap_ok
, and something to be the sync dual oftry_filter_map
. We've also had a little surprise becausetry_filter_map
is actually a combination ofand_then
andtry_filter
, not ofmap
ormap_ok
andtry_filter
, which led to annoyances around types. #2375 has other people being surprised bytry_filter
having an unexpected return type, too, where they wanted one of the other 18 choices that could have been made.The text was updated successfully, but these errors were encountered: