You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
get should accept cellpath specified as string #6597
get accepts symbols of form a.b now (from the REPL) but when defining custom functions, it is awkward to pass in a literal symbol (nu is not lisp, after all), and accidentally passing 'a.b' as a cell path spec for get just surprises users.
How to reproduce
{a: 1, b:{b1:21, b2:22}} | get $s
{a: 1, b:{b1:21, b2:22}} | get b.b1
let s = 'b.b1'
{a: 1, b:{b1:21, b2:22}} | get $s
let data = {a: 1, b:{b1:21, b2:22}}
$s | split row '.' | reduce --fold $data {|it,acc| $acc | get $it}
def my-get [cellpath: string] {let data = $in; $cellpath | split row '.' | reduce --fold $data {|it,acc| $acc | get $it}}
{a: 1, b:{b1:21, b2:22}} | my-get 'b.b1'
Expected behavior
Same behavior as if the passed string literal is passed directly to get at the REPL level (recursively get until done, failing at the earliest non-existent field).
Here is a get variant that emulates the desired behavior as a workaround:
def my-get [cellpath: string] {
let data = $in
$cellpath | split row '.' | reduce --fold $data {|it,acc| $acc | get $it}
}
Screenshots
Here is a simple workaround for get that works better:
Activity
fdncred commentedon Mar 17, 2023
Closing due to #8493