mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 22:57:46 +00:00

Deprecates the existing `stdlib-candidate` directories in `nu_scripts` since `std-rfc` has now transitioned to the main repo. Updates readme and renamed directories.
34 lines
1.3 KiB
Text
34 lines
1.3 KiB
Text
# Convert a record, where each value is a list, into a list of columns.
|
|
# { a: [ 1 2 3 ], b: [ 4 5 6 ] } | record-into-columns
|
|
# => ╭───┬───────────╮
|
|
# => │ 0 │ ╭───┬───╮ │
|
|
# => │ │ │ # │ a │ │
|
|
# => │ │ ├───┼───┤ │
|
|
# => │ │ │ 0 │ 1 │ │
|
|
# => │ │ │ 1 │ 2 │ │
|
|
# => │ │ │ 2 │ 3 │ │
|
|
# => │ │ ╰───┴───╯ │
|
|
# => │ 1 │ ╭───┬───╮ │
|
|
# => │ │ │ # │ b │ │
|
|
# => │ │ ├───┼───┤ │
|
|
# => │ │ │ 0 │ 4 │ │
|
|
# => │ │ │ 1 │ 5 │ │
|
|
# => │ │ │ 2 │ 6 │ │
|
|
# => │ │ ╰───┴───╯ │
|
|
# => ╰───┴───────────╯
|
|
# =>
|
|
# This can be especially useful when combined with `columns-into-table`, as in:
|
|
#
|
|
# { a: [ 1 2 3 ], b: [ 4 5 6 ] } | record-into-columns
|
|
# | columns-into-table
|
|
# => ╭───┬───┬───╮
|
|
# => │ # │ a │ b │
|
|
# => ├───┼───┼───┤
|
|
# => │ 0 │ 1 │ 4 │
|
|
# => │ 1 │ 2 │ 5 │
|
|
# => │ 2 │ 3 │ 6 │
|
|
# => ╰───┴───┴───╯
|
|
# =>
|
|
export def main []: [record -> list] {
|
|
items {|key, val| $val | wrap $key}
|
|
}
|