7a888c9e9b
# Description The previous behaviour of `into record` on lists was to create a new record with each list index as the key. This was not very useful for creating meaningful records, though, and most people would end up using commands like `headers` or `transpose` to turn a list of keys and values into a record. This PR changes that instead to do what I think the most ergonomic thing is, and instead: - A list of records is merged into one record. - A list of pairs (two element lists) is folded into a record with the first element of each pair being the key, and the second being the value. The former is just generally more useful than having to use `reduce` with `merge` for such a common operation, and the latter is useful because it means that `$a | zip $b | into record` *just works* in the way that seems most obvious. Example: ```nushell [[foo bar] [baz quux]] | into record # => {foo: bar, baz: quux} [{foo: bar} {baz: quux}] | into record # => {foo: bar, baz: quux} [foo baz] | zip [bar quux] | into record # => {foo: bar, baz: quux} ``` The support for range input has been removed, as it would no longer reflect the treatment of an equivalent list. The following is equivalent to the old behavior, in case that's desired: ``` 0.. | zip [a b c] | into record # => {0: a, 1: b, 2: c} ``` # User-Facing Changes - `into record` changed as described above (breaking) - `into record` no longer supports range input (breaking) # Tests + Formatting Examples changed to match, everything works. Some usage in stdlib and `nu_plugin_nu_example` had to be changed. # After Submitting - [ ] release notes (commands, breaking change) |
||
---|---|---|
.. | ||
src | ||
std | ||
tests | ||
Cargo.toml | ||
CONTRIBUTING.md | ||
LICENSE | ||
README.md | ||
testing.nu |
Welcome to the standard library of `nushell`!
The standard library is a pure-nushell
collection of custom commands which
provide interactive utilities and building blocks for users writing casual scripts or complex applications.
To see what's here:
> use std
> scope commands | select name usage | where name =~ "std "
#┬───────────name────────────┬──────────────────────usage──────────────────────
0│std assert │Universal assert command
1│std assert equal │Assert $left == $right
2│std assert error │Assert that executing the code generates an error
3│std assert greater │Assert $left > $right
4│std assert greater or equal│Assert $left >= $right
... ...
─┴───────────────────────────┴─────────────────────────────────────────────────
🧰 Using the standard library in the REPL or in scripts
All commands in the standard library must be "imported" into the running environment
(the interactive read-execute-print-loop (REPL) or a .nu
script) using the
use
command.
You can choose to import the whole module, but then must refer to individual commands with a std
prefix, e.g:
use std
std log debug "Running now"
std assert (1 == 2)
Or you can enumerate the specific commands you want to import and invoke them without the std
prefix.
use std ["log debug" assert]
log debug "Running again"
assert (2 == 1)
This is probably the form of import you'll want to add to your env.nu
for interactive use.
✏️ contribute to the standard library
You're invited to contribute to the standard library! See CONTRIBUTING.md for details