Skip to content

get should accept cellpath specified as string #6597

Closed

Description

@hyiltiz

Describe the bug

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

image

Here is a simple workaround for get that works better:
image

Configuration

key value
version 0.68.1
branch
commit_hash
build_os macos-x86_64
build_target x86_64-apple-darwin
rust_version rustc 1.63.0
cargo_version cargo 1.63.0 (fd9c4297c 2022-07-01)
pkg_version 0.68.1
build_time 2022-09-08 20:41:49 +00:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins custom-value generate, custom-value generate2, custom-value update, gstat, inc, nu-example-1, nu-example-2, nu-example-3, query, query json, query web, query xml

Additional context

No response

Activity

  1. fdncred commented on Mar 17, 2023

    @fdncred
    Contributor

    Closing due to #8493

  2. added this to the v0.78.0 milestone on Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions