Repository navigation
Closed
Labels
category:enhancementNew feature or requestsemanticsPlaces where we should define/clarify nushell's semantics
Milestone
Description
Related problem
i have some data i would like to run a closure on top of, without knowing in advance what the exact path in the data is nor the exact value i work with.
this works with a single depth-path, e.g. a, but not with multiple levels, e.g. a.b.c.1
e.g.
- define some data
let data = {a: {b: {c: [1 2 3]}}}- ✔️ this works
>_ let target = "a"
>_ $data | get $target
╭───┬───────────────────╮
│ │ ╭───┬───────────╮ │
│ b │ │ │ ╭───┬───╮ │ │
│ │ │ c │ │ 0 │ 1 │ │ │
│ │ │ │ │ 1 │ 2 │ │ │
│ │ │ │ │ 2 │ 3 │ │ │
│ │ │ │ ╰───┴───╯ │ │
│ │ ╰───┴───────────╯ │
╰───┴───────────────────╯
>_ $data | update $target []
╭───┬────────────────╮
│ a │ [list 0 items] │
╰───┴────────────────╯- ❌ but this does not work
>_ let target = "a.b.c.1"
>_ $data | get $target
Error: nu::shell::column_not_found
× Cannot find column
╭─[entry #14:1:1]
1 │ $data | get $target
· ──┬── ───┬───
· │ ╰── cannot find column 'a.b.c.1'
· ╰── value originates here
╰────
>_ $data | update $target 0
Error: nu::shell::column_not_found
× Cannot find column
╭─[entry #16:1:1]
1 │ $data | update $target 0
· ──┬── ───┬───
· │ ╰── cannot find column 'a.b.c.1'
· ╰── value originates here
╰────Describe the solution you'd like
- with the same data
let data = {a: {b: {c: [1 2 3]}}}- ✔️ this would still work
>_ let target = "a"
>_ $data | get $target
╭───┬───────────────────╮
│ │ ╭───┬───────────╮ │
│ b │ │ │ ╭───┬───╮ │ │
│ │ │ c │ │ 0 │ 1 │ │ │
│ │ │ │ │ 1 │ 2 │ │ │
│ │ │ │ │ 2 │ 3 │ │ │
│ │ │ │ ╰───┴───╯ │ │
│ │ ╰───┴───────────╯ │
╰───┴───────────────────╯
>_ $data | update $target []
╭───┬────────────────╮
│ a │ [list 0 items] │
╰───┴────────────────╯- ✔️ and this would work as well
>_ let target = "a.b.c.1"
>_ $data | get $target
2
>_ $data | update $target 0
╭───┬───────────────────────────╮
│ │ ╭───┬───────────────────╮ │
│ a │ │ │ ╭───┬───────────╮ │ │
│ │ │ b │ │ │ ╭───┬───╮ │ │ │
│ │ │ │ │ c │ │ 0 │ 1 │ │ │ │
│ │ │ │ │ │ │ 1 │ 0 │ │ │ │
│ │ │ │ │ │ │ 2 │ 3 │ │ │ │
│ │ │ │ │ │ ╰───┴───╯ │ │ │
│ │ │ │ ╰───┴───────────╯ │ │
│ │ ╰───┴───────────────────╯ │
╰───┴───────────────────────────╯Describe alternatives you've considered
No response
Additional context and details
No response
Metadata
Metadata
Assignees
Labels
category:enhancementNew feature or requestsemanticsPlaces where we should define/clarify nushell's semantics
Activity
fdncred commentedon Mar 15, 2023
We used to have an
into cellpath(with whatever name cellpath was before it was named cellpath) and then you could do:and it would work. This would be pretty easy to implement if we wanted to go back that direction. Otherwise we could update it to "just work" as one would expect, although I'm not sure how to do that myself right now.
amtoine commentedon Mar 16, 2023
in the end i think this is a simple duplicate of #6597 and being taken care of in #8482 😌
fdncred commentedon Mar 17, 2023
closing due to #8493
amtoine commentedon Mar 17, 2023
niiiice 😋