nushell/crates/nu-std/std
Devyn Cairns 7a888c9e9b
Change behavior of into record on lists to be more useful (#13637)
# 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)
2024-08-22 11:38:43 +02:00
..
assert.nu complete the type of --error-label in std assert commands (#12998) 2024-06-05 08:02:17 +08:00
dirs.nu Refactor error make (#10923) 2023-11-03 10:09:33 -05:00
dt.nu Refactor error make (#10923) 2023-11-03 10:09:33 -05:00
formats.nu Fixes #12482 by pointing help links for ndjson to a non-spam source (take 2) (#12509) 2024-04-13 18:59:43 -05:00
help.nu Return an empty list when no std help --find results are found (#13160) 2024-06-15 12:27:55 -05:00
input.nu Command to get individual keys (#9453) 2023-07-03 10:23:44 -05:00
iter.nu Change behavior of into record on lists to be more useful (#13637) 2024-08-22 11:38:43 +02:00
log.nu fix: Make log respect use_ansi_coloring setting. (#13442) 2024-07-30 08:34:11 -05:00
math.nu move math constants to standard library (#9678) 2023-09-05 19:32:31 +02:00
mod.nu Surprising symlink resolution for std path add (#13258) 2024-06-28 18:11:48 -05:00
xml.nu Refactor error make (#10923) 2023-11-03 10:09:33 -05:00