Return iter from every command (#2118)

* Return iter from `every` command

* Clippy

* Better variable name
This commit is contained in:
Joseph T. Lyons 2020-07-05 22:25:39 -04:00 committed by GitHub
parent 455b1ac294
commit a1a0710ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -73,23 +73,18 @@ async fn every(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputSt
let (EveryArgs { stride, skip }, input) = args.process(&registry).await?;
let v: Vec<_> = input.into_vec().await;
let stride_desired = if stride.item < 1 { 1 } else { stride.item } as usize;
let mut values_vec_deque = VecDeque::new();
for (i, x) in v.iter().enumerate() {
let should_include = if skip.item {
i % stride_desired != 0
} else {
i % stride_desired == 0
};
let iter = v.into_iter().enumerate().filter_map(move |(i, value)| {
let stride_desired = if stride.item < 1 { 1 } else { stride.item } as usize;
let should_include = skip.item == (i % stride_desired != 0);
if should_include {
values_vec_deque.push_back(ReturnSuccess::value(x.clone()));
return Some(ReturnSuccess::value(value));
}
}
Ok(futures::stream::iter(values_vec_deque).to_output_stream())
None
});
Ok(futures::stream::iter(iter).to_output_stream())
}
#[cfg(test)]