From 965e07d8cca1feccc5246deec78f0770f9144c64 Mon Sep 17 00:00:00 2001 From: Chris Gillespie <6572184+gillespiecd@users.noreply.github.com> Date: Sun, 30 Aug 2020 13:50:36 -0700 Subject: [PATCH] Minor updates to variance (#2458) --- crates/nu-cli/src/commands/math/variance.rs | 40 +++++++++++---------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/crates/nu-cli/src/commands/math/variance.rs b/crates/nu-cli/src/commands/math/variance.rs index b081b8050c..893632b836 100644 --- a/crates/nu-cli/src/commands/math/variance.rs +++ b/crates/nu-cli/src/commands/math/variance.rs @@ -81,30 +81,32 @@ impl WholeStreamCommand for SubCommand { entries: column_totals, }) .into_untagged_value()) - }; + }?; - match res { - Ok(v) => { - if v.value.is_table() { - Ok(OutputStream::from( - v.table_entries() - .map(|v| ReturnSuccess::value(v.clone())) - .collect::>(), - )) - } else { - Ok(OutputStream::one(ReturnSuccess::value(v))) - } - } - Err(e) => Err(e), + if res.value.is_table() { + Ok(OutputStream::from( + res.table_entries() + .map(|v| ReturnSuccess::value(v.clone())) + .collect::>(), + )) + } else { + Ok(OutputStream::one(ReturnSuccess::value(res))) } } fn examples(&self) -> Vec { - vec![Example { - description: "Get the variance of a list of numbers", - example: "echo [1 2 3 4 5] | math variance", - result: Some(vec![UntaggedValue::decimal(2).into()]), - }] + vec![ + Example { + description: "Get the variance of a list of numbers", + example: "echo [1 2 3 4 5] | math variance", + result: Some(vec![UntaggedValue::decimal(2).into()]), + }, + Example { + description: "Get the sample variance of a list of numbers", + example: "echo [1 2 3 4 5] | math variance -s", + result: Some(vec![UntaggedValue::decimal(2.5).into()]), + }, + ] } }