Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How can I nest Jsonnet object comprehensions and run the inner loop a different number of times?

$
0
0

I'm trying to figure out how to nest/chain an object comprehension to do something other than a 'full product' and have the inner loop iterate a different amount, but can't figure it out.

{    ["%s-thing-%i" % [grp.name, n]]: {        name: grp.name,        // a bunch of other stuff I don't want to repeat    }    // for n in std.range(1, grp.count)  // invalid, 'Unknown variable: grp'    for n in std.range(1, 3)    for grp    in [{name: "foo", count: 2}, {name: "bar", count: 4}]}

I want a one-level object with two foo-thing-s and four bar-thing-s, but I can't use the count object property like on my commented line as at that point grp is not defined.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>