smol-rs / futures-lite

Futures, streams, and async I/O combinators.
Apache License 2.0
439 stars 25 forks source link

Accept async functions for `StreamExt::map()` and others #48

Open aryan9600 opened 2 years ago

aryan9600 commented 2 years ago

The StreamExt::map(), StreamExt::filter_map() in the futures crate accepts async functions which resolve to an <T>/Option<T>, whereas the same methods in the futures-lite crate accept normal functions which are meant to return <T>/Option<T>. (there are other similar methods as well)

I don't know if this is by design or a mistake, but since this crate is supposed to be fully compatible with the futures crate, I think these methods should be changed accordingly.

taiki-e commented 2 years ago

The current behavior is what was intended by the original author of this crate.

https://github.com/rust-lang/futures-rs/issues/1987#issuecomment-661028051

since this crate is supposed to be fully compatible with the futures crate

Full compatibility is about traits such as streams, not about method signatures. Readme also says:

fixes minor warts in its API, fills in some obvious gaps

aryan9600 commented 2 years ago

I see. Would adding async closures for these methods be considered? (especially if they don't affect compile times that much)

notgull commented 1 year ago

The usual strategy is to use the then() combinator to evaluate an async closure, and then use the result of that in filter_map(), map() etc.