nushell/crates/nu-command/src
Ian Manske 4d3283e235
Change append operator to concatenation operator (#14344)
# Description

The "append" operator currently serves as both the append operator and
the concatenation operator. This dual role creates ambiguity when
operating on nested lists.

```nu
[1 2] ++ 3     # appends a value to a list [1 2 3]
[1 2] ++ [3 4] # concatenates two lists    [1 2 3 4]

[[1 2] [3 4]] ++ [5 6]
# does this give [[1 2] [3 4] [5 6]]
# or             [[1 2] [3 4] 5 6]  
```

Another problem is that `++=` can change the type of a variable:
```nu
mut str = 'hello '
$str ++= ['world']
($str | describe) == list<string>
```

Note that appending is only relevant for lists, but concatenation is
relevant for lists, strings, and binary values. Additionally, appending
can be expressed in terms of concatenation (see example below). So, this
PR changes the `++` operator to only perform concatenation.

# User-Facing Changes

Using the `++` operator with a list and a non-list value will now be a
compile time or runtime error.
```nu
mut list = []
$list ++= 1 # error
```
Instead, concatenate a list with one element:
```nu
$list ++= [1]
```
Or use `append`:
```nu
$list = $list | append 1
```

# After Submitting

Update book and docs.

---------

Co-authored-by: Douglas <32344964+NotTheDr01ds@users.noreply.github.com>
2024-11-24 10:59:54 -08:00
..
bytes Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
charting Replace raw usize IDs with new types (#13832) 2024-09-30 13:20:15 +02:00
conversions Fix ignored into datetime test (#14302) 2024-11-11 06:01:39 -06:00
database Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
date Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
debug remove terminal_size crate everywhere it makes sense (#14423) 2024-11-23 19:37:12 -08:00
env Always load default env/config values (#14249) 2024-11-20 16:15:15 -06:00
experimental Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
filesystem Rely on display_output hook for formatting values from evaluations (#14361) 2024-11-19 21:04:29 +08:00
filters Deprecate split-by command (#14019) 2024-11-21 10:47:03 +01:00
formats truly flexible csv/tsv parsing (#14399) 2024-11-21 15:58:31 -06:00
generators Seq char update will work on all char (#14261) 2024-11-15 21:05:29 +01:00
hash add binary as input to hash commands (#13923) 2024-09-25 16:47:52 +08:00
help Change append operator to concatenation operator (#14344) 2024-11-24 10:59:54 -08:00
math Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
misc Replace raw usize IDs with new types (#13832) 2024-09-30 13:20:15 +02:00
network command/http/client use CRLF for headers join instead of LF (#14417) 2024-11-23 13:49:25 -08:00
path fix path exists on a non-directory file (#13763) 2024-09-11 12:45:39 -05:00
platform remove terminal_size crate everywhere it makes sense (#14423) 2024-11-23 19:37:12 -08:00
random support filesize arguments in random binary/chars (#14068) 2024-10-12 14:49:05 +08:00
removed Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
shells Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
stor feat: stor insert accepts lists (#14175) 2024-10-29 06:32:55 -05:00
strings remove deprecated warnings (#14386) 2024-11-19 07:52:58 -06:00
system allow ps1 files to be executed without pwsh/powershell -c file.ps1 (#14379) 2024-11-20 21:55:26 +08:00
viewers remove terminal_size crate everywhere it makes sense (#14423) 2024-11-23 19:37:12 -08:00
default_context.rs Add utouch command from uutils/coreutils (#11817) 2024-11-17 18:03:21 -06:00
example_test.rs Overhaul $in expressions (#13357) 2024-07-17 16:02:42 -05:00
lib.rs Add top-level crate documentation/READMEs (#12907) 2024-07-14 10:10:41 +02:00
progress_bar.rs Cut down unnecessary lint allows (#14335) 2024-11-15 19:24:39 +01:00
sort_utils.rs Rework sorting and add cell path and closure comparators to sort-by (#13154) 2024-10-09 19:18:16 -07:00