Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding multiple fields to a list #1173

Closed
MikkelHJuul opened this issue Jul 30, 2021 · 3 comments
Closed

Adding multiple fields to a list #1173

MikkelHJuul opened this issue Jul 30, 2021 · 3 comments
Labels
FeatureRequest New feature or request

Comments

@MikkelHJuul
Copy link

When working with lists and conditional elements, when trying to add multiple conditional elements one has to wrap all of these with the condition.

This is the only valid syntax:

asd: [
   "a",
   if _cond {
      "s"
   },
   if _cond {
      "d",
    },
]

There are two possible solutions:
allow multiple objects in the conditional

asd: [
  "a",
  if _cond {
     "s",
     "d",
   },   //dangling comma??
]

or the slightly wider solution
"Multiple references to a list object appends to that list" (sounds like a big change to the language)

asd: [
   "a",
]
if _cond {
   asd: [
      "s",
      "d",
    ]
}

The latter would enable better separation of objects across files, but it seems like a thing that may be impossible to add without enabling/messing with the scope etc. of the internals.
I originally thought this solution was there in the language, it follows the thought of allowing reference of fields disjointly:

a: b: string
a: c: string

but I do see that it's harder when you are referencing an array/list (opposed to a field -- in essence you are referencing the same field).

These help avoid having to use indirection, and list-flattening

_listA: [...]
_listB: [...]
list: {
   if _cond {
      list.FlattenN([_listA,_listB], 1) 
   }
   if !_cond {
      _listA
   }
}

** Additional context **
I wrongfully tried it myself, and had to fix:
MikkelHJuul/ODIM-H5-Validator@1e1aaa1

@MikkelHJuul MikkelHJuul added FeatureRequest New feature or request Triage Requires triage/attention labels Jul 30, 2021
@myitcv
Copy link
Member

myitcv commented Jul 30, 2021

@MikkelHJuul thanks for raising this. Please see #165 (comment); there are plans for addressing this in the query extension proposal. Hence I'll mark this issue as closed, but please shout if you think I've missed something.

@myitcv myitcv closed this as completed Jul 30, 2021
@myitcv myitcv removed the Triage Requires triage/attention label Jul 30, 2021
@MikkelHJuul
Copy link
Author

@MikkelHJuul thanks for raising this. Please see #165 (comment); there are plans for addressing this in the query extension proposal. Hence I'll mark this issue as closed, but please shout if you think I've missed something.

Great, sorry for missing it, I searched for conditional and found nothing. It looks like an implementation of a "spread" operator, very neat and that would certainly fix the issue

@myitcv
Copy link
Member

myitcv commented Jul 30, 2021

Great, sorry for missing it, I searched for conditional and found nothing.

Absolutely no apology required; finding things is hard at the best of times, let alone when the terminology might be different!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants