Record destructuring
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 40.5k
- Forks
- 2.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 85
Description
Related problem
Let's take ls as an example, suppose we want to perform some operations on a file name in the current working directory:
ls | each { |it|
do-some-stuff $it.name
do-some-stuff $it.name
do-some-stuff $it.name
do-some-stuff $it.name
}
Taking all the it fields in the scope it's cognitive heavier and requires the user to make a lot of typing when using a field more than 2/3 time, so someone will be tempted to just declare a new variable inside a block
ls | each { |it|
let name = $it.name
do-some-stuff $name
do-some-stuff $name
do-some-stuff $name
do-some-stuff $name
}
Describe the solution you'd like
Support object destructuring directly in the block parameter
ls | each { |{ name }|
do-some-stuff $name
do-some-stuff $name
do-some-stuff $name
do-some-stuff $name
}
Another cool idea could be supporting the same syntax inside a let definition like:
let { a, b, c } = do-some-stuff "test"
And maybe support directly renaming properties
let { a: an_a_alias } = do-some-stuff "test"
echo $an_a_alias
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
Start by reproducing the block-parameter example in Nushell and compare it with the proposed let-destructuring and property-renaming forms. Define which forms are in scope and verify that destructured names work in the block or let body, with tests covering the accepted syntax and resulting values.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100