github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/eval/comprehensions.txtar (about)

     1  -- in.cue --
     2  import "strings"
     3  
     4  a: {x: 10, y: 100, z: 50}
     5  b: {
     6  	for k, v in a if v <= 50 {
     7  		"\(k)": v
     8  	}
     9  	x: int
    10  	if x > 3 {
    11  		k: 20
    12  	}
    13  	k: int
    14  	if k > 0 {
    15  		l: 40
    16  	}
    17  }
    18  
    19  c: {
    20  	for k, v in a let y = v + 10 if y > 50 {
    21  		"\(k)": y
    22  	}
    23  }
    24  
    25  A: X: run: "dfoo"
    26  
    27  if true {
    28  	A: X: {
    29  		run:   string
    30  		files: "\(strings.Join([ run], "\n"))"
    31  	}
    32  }
    33  -- out/eval --
    34  (struct){
    35    a: (struct){
    36      x: (int){ 10 }
    37      y: (int){ 100 }
    38      z: (int){ 50 }
    39    }
    40    b: (struct){
    41      x: (int){ 10 }
    42      k: (int){ 20 }
    43      z: (int){ 50 }
    44      l: (int){ 40 }
    45    }
    46    c: (struct){
    47      y: (int){ 110 }
    48      z: (int){ 60 }
    49    }
    50    A: (struct){
    51      X: (struct){
    52        run: (string){ "dfoo" }
    53        files: (string){ "dfoo" }
    54      }
    55    }
    56  }
    57  -- out/compile --
    58  --- in.cue
    59  {
    60    a: {
    61      x: 10
    62      y: 100
    63      z: 50
    64    }
    65    b: {
    66      for k, v in 〈1;a〉 if (〈0;v〉 <= 50) {
    67        "\(〈1;k〉)": 〈1;v〉
    68      }
    69      x: int
    70      if (〈0;x〉 > 3) {
    71        k: 20
    72      }
    73      k: int
    74      if (〈0;k〉 > 0) {
    75        l: 40
    76      }
    77    }
    78    c: {
    79      for k, v in 〈1;a〉 let y = (〈0;v〉 + 10) if (〈0;y〉 > 50) {
    80        "\(〈2;k〉)": 〈1;y〉
    81      }
    82    }
    83    A: {
    84      X: {
    85        run: "dfoo"
    86      }
    87    }
    88    if true {
    89      A: {
    90        X: {
    91          run: string
    92          files: "\(〈import;strings〉.Join([
    93            〈1;run〉,
    94          ], "\n"))"
    95        }
    96      }
    97    }
    98  }