From 7e070e2e5b1f7b36f65b2d01c2f1ec2f0e6745c4 Mon Sep 17 00:00:00 2001 From: Luccas Mateus Date: Sat, 6 Nov 2021 22:20:58 -0300 Subject: [PATCH] Fix "`math sum` doesn't support streams" (#301) * MathEval Variance and Stddev * Fix tests and linting * Typo * Deal with streams when they are not tables --- crates/nu-command/src/math/utils.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/src/math/utils.rs b/crates/nu-command/src/math/utils.rs index 32d28d6414..aef8f2ce21 100644 --- a/crates/nu-command/src/math/utils.rs +++ b/crates/nu-command/src/math/utils.rs @@ -16,7 +16,7 @@ pub fn run_with_function( } fn helper_for_tables( - values: PipelineData, + values: &[Value], name: Span, mf: impl Fn(&[Value], &Span) -> Result, ) -> Result { @@ -31,6 +31,9 @@ fn helper_for_tables( .and_modify(|v: &mut Vec| v.push(value.clone())) .or_insert_with(|| vec![value.clone()]); } + } else { + //Turns out we are not dealing with a table + return mf(values, &name); } } // The mathematical function operates over the columns of the table @@ -67,9 +70,9 @@ pub fn calculate( mf: impl Fn(&[Value], &Span) -> Result, ) -> Result { match values { - PipelineData::Stream(_) => helper_for_tables(values, name, mf), + PipelineData::Stream(s) => helper_for_tables(&s.collect::>(), name, mf), PipelineData::Value(Value::List { ref vals, .. }) => match &vals[..] { - [Value::Record { .. }, _end @ ..] => helper_for_tables(values, name, mf), + [Value::Record { .. }, _end @ ..] => helper_for_tables(vals, name, mf), _ => mf(vals, &name), }, PipelineData::Value(Value::Record { vals, cols, span }) => {