Skip to content

Commit

Permalink
implement the first transposition for tables
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Sep 9, 2023
1 parent ee51ad0 commit 596fcd8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/nu/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,25 @@ pub(crate) fn transpose(value: &Value) -> Value {
}
}

return value.clone();
match value {
Value::List { vals, .. } => {
let mut rows = vec![];
for col in vals[0].columns() {
let mut cols = vec!["1".into()];
let mut vs = vec![Value::string(col, Span::unknown())];

for (i, v) in vals.iter().enumerate() {
cols.push(format!("{}", i + 2));
vs.push(v.get_data_by_key(col).unwrap());
}

rows.push(Value::record(Record { cols, vals: vs }, Span::unknown()));
}

return Value::list(rows, Span::unknown());
}
_ => return value.clone(),
}
}

match value {
Expand Down

0 comments on commit 596fcd8

Please sign in to comment.