-
Notifications
You must be signed in to change notification settings - Fork 23
Should it be possible to deconstruct structs? #346
Copy link
Copy link
Open
Labels
specification 1.1Ion 1.1 specification workIon 1.1 specification work
Description
There is no way to deconstruct a struct value or access the field names of a struct, which means that there is no way for a user to create a macro that can do something like this:
(:foo 1 2 3 { 'api-version':2, 'client-request-id': "yF8q3pZKRZ3dDfzaNy6N" })
=>
{
foo: 1,
bar: 2,
baz: 3,
'X-api-version': 2,
'X-client-request-id': "yF8q3pZKRZ3dDfzaNy6N"
}
Hypothetically, one might be able to allow flatten to flatten a struct into pairs of field names and values, and then add some syntax to for that can bind to both the field name and the value, enabling the creation of a macro like this:
(macro foo (foo bar baz additional_properties)
(make_struct
((.literal foo) foo)
((.literal bar) bar)
((.literal baz) baz)
(.for (( [name, value] (.flatten additional_properties))
(.field (make_string "X-" name) value)))
However, this is not necessarily the only or optimal solution.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
specification 1.1Ion 1.1 specification workIon 1.1 specification work