Skip to content

Call a function on every element of a complex value #4610

@philrz

Description

@philrz

Repro is with Zed commit efdcd27.

Imagine you have an complex value such as the array of numbers [1, 4, 9, 16] and you want to execute some function on each element to produce a new array, such as multiplying each element by two. To accomplish this in Zed today requires a multi-part idiom:

$ zq -version
Version: v1.8.0-5-gefdcd272

$ echo '[1, 4, 9, 16]' | zq -z 'over this | yield this*2 | collect(this)' -
[2,8,18,32]

Compare this to something like JavaScript's map() (not to be confused with Zed's map type) which can perform the equivalent in one shot. We've recognized Zed should offer a similar shorthand.

While in JavaScript we see this approach applied to array types, it seems that in Zed it could be used for not only arrays but also sets, maybe maps, and perhaps into records (recursively?) though I'm not sure. Implementation TBD, I suppose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions