Dynamic two-way references. #907
Replies: 3 comments 3 replies
-
In principle you should be able to map one object to another without getting into cycle issues. But there is an issue with comprehensions and spurious cycles, see #779. Adding new fields to a map would be okay as long as the modified fields would not influence the comprehension, which is the case here. For now, if it is workable for you to define a duplicate object with the expanded results, you could write:
|
Beta Was this translation helpful? Give feedback.
-
This is a nice case to test against the query proposal, btw. With the query proposal implemented and the for cycle bug fix, this could be written as:
The proposed associative array feature allows one to interpret lists as maps, keyed on some string derived from the list elements. One would have to separately enforce that references exist and are unique. |
Beta Was this translation helpful? Give feedback.
-
This discussion has been migrated to cue-lang/cue#907. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
Beta Was this translation helpful? Give feedback.
-
Hello Community.
Our goal is that any #Object.mappings defined in one spot should show up as the inverse in the second #Object.mappings on compilation such that both Objects are aware that they are mapped to each other, but we only have to establish the relationship in one spot for simplicity. While it totally works to define the mappings in two places, we'd like to be more dynamic in generating these mappings to save time. The closest we've been able to get is to utilize for loops to go through every #Object.mappings element and try to generate the inverse, but we are struggling to modify the referenced object. In our example, this would be iterating through Beta.Beta1.mappings to create Alpha.Alpha1.mappings that point back to Beta1. Another potential solution we've come up with is breaking up the to: element in mappings into separate variables, which somewhat works but ends up with extraneous output (and is a bit verbose). An added element of difficulty is that #Objects can be nested in other #Objects, which potentially introduces some element of infinite looping issues?
and
With the ideal scenario being something like:
With this output:
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions