mirror of
https://github.com/nushell/nushell.git
synced 2024-12-15 03:32:50 +01:00
24 lines
660 B
Rust
24 lines
660 B
Rust
use crate::errors::ShellError;
|
|
use crate::object::Block;
|
|
use crate::prelude::*;
|
|
use futures::future::ready;
|
|
use log::trace;
|
|
|
|
command! {
|
|
Where as where(args, condition: Block,) {
|
|
let input: InputStream = trace_stream!(target: "nu::trace_stream::where", "where input" = args.input);
|
|
|
|
input.values.filter_map(move |item| {
|
|
let result = condition.invoke(&item);
|
|
|
|
let return_value = match result {
|
|
Err(err) => Some(Err(err)),
|
|
Ok(v) if v.is_true() => Some(Ok(ReturnSuccess::Value(item.clone()))),
|
|
_ => None,
|
|
};
|
|
|
|
ready(return_value)
|
|
})
|
|
}
|
|
}
|