-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Introduce a spread operator #10598
Description
Related problem
Spread operator, the process of de-structuring as they call it in javascript.
Essentially, an elegant way to unpack objects, or records in our case, arrays and other data types which may be eligible without the need of introducing another component in the pipeline.
Destructuring record members
let rec = {a: 1, b: 2}
let updated_rec = {...$rec, c: 4 }as an alternative to its counterpart
let rec = {a: 1, b: 2}
let updated_rec = ($rec | merge {c: 4})Example using a list:
$env.config.keybindings = ($env.config.keybindings | append {
name: delete_one_word_forward
modifier: control
keycode: char_d
mode: emacs
event: {edit: deleteword}
})Could be written as:
$env.config.keybindings = [
...$env.config.keybindings
{
name: delete_one_word_forward
modifier: control
keycode: char_d
mode: emacs
event: {edit: deleteword}
}
]It allows for the omission of the pipe operator, hence the wrapping parentheses are omitted as well.
Another example of spreading into a list:
[10..0] | reduce -f [] {|i,a| [...$a $"Ready in ($i)" }Describe the solution you'd like
There is already a similar syntax built in to the language, so using the triple dot operator seems to make sense as well, but its likely up for debate.
I composed the draft rather quickly so I didn't put a lot of thinking into demonstrating how it could improve the syntax amongst many cases but I'm sure there are better examples than the ones cited above.
Describe alternatives you've considered
The de-facto append.
Additional context and details
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax