Mutable "pipeline assignment" operator
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 40.5k
- Forks
- 2.3k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 79
Description
Related problem
I'm not sure if I have the naming right, but when dealing with config (or other mutable variables), the convenience of the += and ++= operators only goes so far. When dealing with, for instance, a record that needs a merge, you still have to resort to $variable = $variable | merge {}.
We currently have:
╭───┬──────────┬────────────────╮
│ # │ operator │ name │
├───┼──────────┼────────────────┤
│ 0 │ += │ PlusAssign │
│ 1 │ ++= │ ConcatAssign │
│ 2 │ -= │ MinusAssign │
│ 3 │ *= │ MultiplyAssign │
│ 4 │ /= │ DivideAssign │
╰───┴──────────┴────────────────╯
Describe the solution you'd like
A PipeAssign operator, probably |= which would allow a RHS expression that would simply use the value of the LHS as pipeline input. For example:
mut foo = "foo"
$foo |= str upcase
$foo
# => FOO
This comes in handy with longer $env.config entries.
# Without operator:
$env.config.hooks.env_change = (
$env.config.hooks.env_change
| merge deep --strategy=append {
PWD: [{|before,after| null }]
}
)
# With operator
$env.config.hooks.env_change |= merge deep --strategy=append {
PWD: [{|before,after| null }]
}
Describe alternatives you've considered
No response
Additional context and details
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or entry points. Begin by tracing the existing += and ++= assignment operators in the Nushell source, then establish the scope and acceptance cases for |= from the examples, including mutable variables and nested $env.config paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, shell
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100