forked from extern/nushell
Split OutputStream into ActionStream/OutputStream (#3304)
* Split OutputStream into ActionStream/OutputStream * Fmt * Missed update * Cleanup helper names * Fmt
This commit is contained in:
@ -18,7 +18,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Returns absolute values of a list of numbers"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let mapped = args.input.map(move |val| match val.value {
|
||||
UntaggedValue::Primitive(Primitive::Int(val)) => {
|
||||
UntaggedValue::int(val.magnitude().clone()).into()
|
||||
@ -31,7 +31,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
}
|
||||
other => abs_default(other),
|
||||
});
|
||||
Ok(OutputStream::from_input(mapped))
|
||||
Ok(ActionStream::from_input(mapped))
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@ -27,7 +27,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Finds the average of a list of numbers or tables"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
run_with_function(args, average)
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Applies the ceil function to a list of numbers"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let input = args.input;
|
||||
|
||||
run_with_numerical_functions_on_stream(input, ceil_big_int, ceil_big_decimal, ceil_default)
|
||||
|
@ -18,8 +18,8 @@ impl WholeStreamCommand for Command {
|
||||
"Use mathematical functions as aggregate functions on a list of numbers or tables."
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
Ok(OutputStream::one(Ok(ReturnSuccess::Value(
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
Ok(ActionStream::one(Ok(ReturnSuccess::Value(
|
||||
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
|
||||
))))
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
)
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
eval(args)
|
||||
}
|
||||
|
||||
@ -45,13 +45,13 @@ impl WholeStreamCommand for SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eval(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
pub fn eval(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.span;
|
||||
let (SubCommandArgs { expression }, input) = args.process()?;
|
||||
|
||||
if let Some(string) = expression {
|
||||
match parse(&string, &string.tag) {
|
||||
Ok(value) => Ok(OutputStream::one(ReturnSuccess::value(value))),
|
||||
Ok(value) => Ok(ActionStream::one(ReturnSuccess::value(value))),
|
||||
Err(err) => Err(ShellError::labeled_error(
|
||||
"Math evaluation error",
|
||||
err,
|
||||
@ -89,7 +89,7 @@ pub fn eval(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
))
|
||||
}
|
||||
})
|
||||
.to_output_stream())
|
||||
.to_action_stream())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Applies the floor function to a list of numbers"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let input = args.input;
|
||||
|
||||
run_with_numerical_functions_on_stream(
|
||||
|
@ -20,7 +20,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Finds the maximum within a list of numbers or tables"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
run_with_function(args, maximum)
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Gets the median of a list of numbers"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
run_with_function(args, median)
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Finds the minimum within a list of numbers or tables"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
run_with_function(args, minimum)
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Gets the most frequent element(s) from a list of numbers or tables"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
run_with_function(args, mode)
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Finds the product of a list of numbers or tables"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
run_with_function(args, product)
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Applies the round function to a list of numbers"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
operate(args)
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (Arguments { precision }, input) = args.process()?;
|
||||
let precision = precision.map(|p| p.item).unwrap_or(0);
|
||||
|
||||
@ -66,7 +66,7 @@ fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
UntaggedValue::Primitive(Primitive::Decimal(val)) => round_big_decimal(val, precision),
|
||||
other => round_default(other),
|
||||
});
|
||||
Ok(OutputStream::from_input(mapped))
|
||||
Ok(ActionStream::from_input(mapped))
|
||||
}
|
||||
|
||||
fn round_big_int(val: BigInt) -> Value {
|
||||
|
@ -18,7 +18,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Applies the square root function to a list of numbers"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
Ok(operate(args))
|
||||
}
|
||||
|
||||
@ -34,13 +34,13 @@ impl WholeStreamCommand for SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
fn operate(args: CommandArgs) -> OutputStream {
|
||||
fn operate(args: CommandArgs) -> ActionStream {
|
||||
let mapped = args.input.map(move |val| match val.value {
|
||||
UntaggedValue::Primitive(Primitive::Int(val)) => sqrt_big_decimal(BigDecimal::from(val)),
|
||||
UntaggedValue::Primitive(Primitive::Decimal(val)) => sqrt_big_decimal(val),
|
||||
other => sqrt_default(other),
|
||||
});
|
||||
OutputStream::from_input(mapped)
|
||||
ActionStream::from_input(mapped)
|
||||
}
|
||||
|
||||
fn sqrt_big_decimal(val: BigDecimal) -> Value {
|
||||
|
@ -30,7 +30,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Finds the stddev of a list of numbers or tables"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (Arguments { sample }, mut input) = args.process()?;
|
||||
|
||||
@ -81,13 +81,13 @@ impl WholeStreamCommand for SubCommand {
|
||||
}?;
|
||||
|
||||
if res.value.is_table() {
|
||||
Ok(OutputStream::from(
|
||||
Ok(ActionStream::from(
|
||||
res.table_entries()
|
||||
.map(|v| ReturnSuccess::value(v.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
))
|
||||
} else {
|
||||
Ok(OutputStream::one(ReturnSuccess::value(res)))
|
||||
Ok(ActionStream::one(ReturnSuccess::value(res)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Finds the sum of a list of numbers or tables"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
run_with_function(args, summation)
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ pub type MathFunction = fn(values: &[Value], tag: &Tag) -> Result<Value, ShellEr
|
||||
pub fn run_with_function(
|
||||
args: impl Into<RunnableContext>,
|
||||
mf: MathFunction,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
) -> Result<ActionStream, ShellError> {
|
||||
let RunnableContext {
|
||||
mut input,
|
||||
call_info,
|
||||
@ -23,13 +23,13 @@ pub fn run_with_function(
|
||||
match res {
|
||||
Ok(v) => {
|
||||
if v.value.is_table() {
|
||||
Ok(OutputStream::from(
|
||||
Ok(ActionStream::from(
|
||||
v.table_entries()
|
||||
.map(|v| ReturnSuccess::value(v.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
))
|
||||
} else {
|
||||
Ok(OutputStream::one(ReturnSuccess::value(v)))
|
||||
Ok(ActionStream::one(ReturnSuccess::value(v)))
|
||||
}
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
@ -47,13 +47,13 @@ pub fn run_with_numerical_functions_on_stream(
|
||||
int_function: IntFunction,
|
||||
decimal_function: DecimalFunction,
|
||||
default_function: DefaultFunction,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
) -> Result<ActionStream, ShellError> {
|
||||
let mapped = input.map(move |val| match val.value {
|
||||
UntaggedValue::Primitive(Primitive::Int(val)) => int_function(val),
|
||||
UntaggedValue::Primitive(Primitive::Decimal(val)) => decimal_function(val),
|
||||
other => default_function(other),
|
||||
});
|
||||
Ok(OutputStream::from_input(mapped))
|
||||
Ok(ActionStream::from_input(mapped))
|
||||
}
|
||||
|
||||
pub fn calculate(values: &[Value], name: &Tag, mf: MathFunction) -> Result<Value, ShellError> {
|
||||
|
@ -28,7 +28,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Finds the variance of a list of numbers or tables"
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (Arguments { sample }, mut input) = args.process()?;
|
||||
|
||||
@ -79,13 +79,13 @@ impl WholeStreamCommand for SubCommand {
|
||||
}?;
|
||||
|
||||
if res.value.is_table() {
|
||||
Ok(OutputStream::from(
|
||||
Ok(ActionStream::from(
|
||||
res.table_entries()
|
||||
.map(|v| ReturnSuccess::value(v.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
))
|
||||
} else {
|
||||
Ok(OutputStream::one(ReturnSuccess::value(res)))
|
||||
Ok(ActionStream::one(ReturnSuccess::value(res)))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user