forked from extern/nushell
Minor stddev updates (#2452)
1. Add an example for getting the sample stddev 2. Opt for ? instead of generic Err match
This commit is contained in:
parent
634bb688c1
commit
84a6010f71
@ -83,30 +83,32 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
entries: column_totals,
|
entries: column_totals,
|
||||||
})
|
})
|
||||||
.into_untagged_value())
|
.into_untagged_value())
|
||||||
};
|
}?;
|
||||||
|
|
||||||
match res {
|
if res.value.is_table() {
|
||||||
Ok(v) => {
|
Ok(OutputStream::from(
|
||||||
if v.value.is_table() {
|
res.table_entries()
|
||||||
Ok(OutputStream::from(
|
.map(|v| ReturnSuccess::value(v.clone()))
|
||||||
v.table_entries()
|
.collect::<Vec<_>>(),
|
||||||
.map(|v| ReturnSuccess::value(v.clone()))
|
))
|
||||||
.collect::<Vec<_>>(),
|
} else {
|
||||||
))
|
Ok(OutputStream::one(ReturnSuccess::value(res)))
|
||||||
} else {
|
|
||||||
Ok(OutputStream::one(ReturnSuccess::value(v)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => Err(e),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![Example {
|
vec![
|
||||||
description: "Get the stddev of a list of numbers",
|
Example {
|
||||||
example: "echo [1 2 3 4 5] | math stddev",
|
description: "Get the stddev of a list of numbers",
|
||||||
result: Some(vec![UntaggedValue::decimal(BigDecimal::from_str("1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573").expect("Could not convert to decimal from string")).into()]),
|
example: "echo [1 2 3 4 5] | math stddev",
|
||||||
}]
|
result: Some(vec![UntaggedValue::decimal(BigDecimal::from_str("1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573").expect("Could not convert to decimal from string")).into()]),
|
||||||
|
},
|
||||||
|
Example {
|
||||||
|
description: "Get the sample stddev of a list of numbers",
|
||||||
|
example: "echo [1 2 3 4 5] | math stddev -s",
|
||||||
|
result: Some(vec![UntaggedValue::decimal(BigDecimal::from_str("1.581138830084189665999446772216359266859777569662608413428752426396297219319619110672124054189650148").expect("Could not convert to decimal from string")).into()]),
|
||||||
|
},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user