Skip to content

Commit 4c2daad

Browse files
committed
Reduce the code of stream::map
1 parent a3ceeac commit 4c2daad

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/stream.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@ pub fn map<St, U, F>(stream: St, f: F) -> impl Stream<Item = U>
2727
where F: FnMut(St::Item) -> U,
2828
St: Stream + Unpin,
2929
{
30-
futures::stream::unfold((stream, f), move |(mut stream, mut f)| {
31-
async {
32-
if let Some(item) = await!(next(&mut stream)) {
33-
let mapped = f(item);
34-
Some((mapped, (stream, f)))
35-
} else {
36-
None
37-
}
38-
}
30+
futures::stream::unfold((stream, f), async move |(mut stream, mut f)| {
31+
let item = await!(next(&mut stream));
32+
item.map(|item| (f(item), (stream, f)))
3933
})
4034
}
4135

0 commit comments

Comments
 (0)