mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2024-05-28 16:38:08 +00:00
Combine map_ok and map_err underlying impl
This commit is contained in:
parent
2b10c48619
commit
4a5b9712aa
|
@ -58,6 +58,22 @@ where
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn map<S, I1, I2, F>(stream: S, f: F) -> impl Stream<Item = I2>
|
||||||
|
where
|
||||||
|
S: Stream<Item = I1>,
|
||||||
|
I2: 'static,
|
||||||
|
F: Fn(I1) -> I2 + Copy,
|
||||||
|
{
|
||||||
|
streem::from_fn(|yielder| async move {
|
||||||
|
let stream = std::pin::pin!(stream);
|
||||||
|
let mut streamer = stream.into_streamer();
|
||||||
|
|
||||||
|
while let Some(res) = streamer.next().await {
|
||||||
|
yielder.yield_((f)(res)).await;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "io-uring"))]
|
#[cfg(not(feature = "io-uring"))]
|
||||||
pub(crate) fn map_ok<S, T1, T2, E, F>(stream: S, f: F) -> impl Stream<Item = Result<T2, E>>
|
pub(crate) fn map_ok<S, T1, T2, E, F>(stream: S, f: F) -> impl Stream<Item = Result<T2, E>>
|
||||||
where
|
where
|
||||||
|
@ -66,14 +82,7 @@ where
|
||||||
E: 'static,
|
E: 'static,
|
||||||
F: Fn(T1) -> T2 + Copy,
|
F: Fn(T1) -> T2 + Copy,
|
||||||
{
|
{
|
||||||
streem::from_fn(|yielder| async move {
|
map(stream, move |res| res.map(f))
|
||||||
let stream = std::pin::pin!(stream);
|
|
||||||
let mut streamer = stream.into_streamer();
|
|
||||||
|
|
||||||
while let Some(res) = streamer.next().await {
|
|
||||||
yielder.yield_(res.map(f)).await;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn map_err<S, T, E1, E2, F>(stream: S, f: F) -> impl Stream<Item = Result<T, E2>>
|
pub(crate) fn map_err<S, T, E1, E2, F>(stream: S, f: F) -> impl Stream<Item = Result<T, E2>>
|
||||||
|
@ -83,14 +92,7 @@ where
|
||||||
E2: 'static,
|
E2: 'static,
|
||||||
F: Fn(E1) -> E2 + Copy,
|
F: Fn(E1) -> E2 + Copy,
|
||||||
{
|
{
|
||||||
streem::from_fn(|yielder| async move {
|
map(stream, move |res| res.map_err(f))
|
||||||
let stream = std::pin::pin!(stream);
|
|
||||||
let mut streamer = stream.into_streamer();
|
|
||||||
|
|
||||||
while let Some(res) = streamer.next().await {
|
|
||||||
yielder.yield_(res.map_err(f)).await;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_err<S, T, E1, E2>(stream: S) -> impl Stream<Item = Result<T, E2>>
|
pub(crate) fn from_err<S, T, E1, E2>(stream: S) -> impl Stream<Item = Result<T, E2>>
|
||||||
|
|
Loading…
Reference in a new issue