mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:45:56 +02:00
to csv
and to tsv
(#412)
* MathEval Variance and Stddev * Fix tests and linting * Typo * Deal with streams when they are not tables * ToTsv and ToCsv
This commit is contained in:
@ -287,6 +287,38 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_data_by_key(&self, name: &str) -> Option<Value> {
|
||||
match self {
|
||||
Value::Record { cols, vals, .. } => cols
|
||||
.iter()
|
||||
.zip(vals.iter())
|
||||
.find(|(col, _)| col == &name)
|
||||
.map(|(_, val)| val.clone()),
|
||||
Value::List { vals, span } => {
|
||||
let mut out = vec![];
|
||||
for item in vals {
|
||||
match item {
|
||||
Value::Record { .. } => match item.get_data_by_key(name) {
|
||||
Some(v) => out.push(v),
|
||||
None => out.push(Value::nothing(*span)),
|
||||
},
|
||||
_ => out.push(Value::nothing(*span)),
|
||||
}
|
||||
}
|
||||
|
||||
if !out.is_empty() {
|
||||
Some(Value::List {
|
||||
vals: out,
|
||||
span: *span,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert Value into string. Note that Streams will be consumed.
|
||||
pub fn into_string(self, separator: &str, config: &Config) -> String {
|
||||
match self {
|
||||
|
Reference in New Issue
Block a user