Dynamic keys in multi-select-hash #92
innovate-invent
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I often want to be able to specify a key name dynamically when defining a multi-select-hash:
{expression1: expression2}
where the result of expression1 is the key for that key-value.The key is already spec'd as an unquoted identifier which is used literally rather than searching the current context. This collides with the ability to use an expression:
search({a: "foo", bar: 5}, {a: bar}) -> {a: 5}
a is used literally rather than trying to de-reference it as "foo" resulting in{foo: 5}
.This could be worked around by using parenthesis when wanting a dynamic key:
{(a): bar}
->{foo: 5}
. This is similar to Computed Property Names in Javascript.This feature becomes more important when you consider its use with reduce():
search([["foo", 1], ["bar", 2]], &[%].$+{[ @[0] ]: @[1]}) -> {foo: 1, bar: 2}
This is the equivalent to the proposed from_items()
The proposed grammar change would be:
Originally mentioned here
Beta Was this translation helpful? Give feedback.
All reactions