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

     1  -- in.cue --
     2  b: {for k, v in a {"\(k)": v + 1}}
     3  a: {b: 1, c: 2}
     4  
     5  x: {for k, v in y {"\(k)": v}}
     6  y: {} // check that empty struct after reference works.
     7  
     8  k: {for v in e {v}}
     9  e: int
    10  
    11  comprehensionBinds: {
    12  	a: {for _ in [1] {a: _}}
    13  	b: {for _, _ in [1] {a: _}}
    14  }
    15  -- out/eval --
    16  Errors:
    17  k: invalid operand e (found int, want list or struct):
    18      ./in.cue:7:14
    19  
    20  Result:
    21  (_|_){
    22    // [eval]
    23    b: (struct){
    24      b: (int){ 2 }
    25      c: (int){ 3 }
    26    }
    27    a: (struct){
    28      b: (int){ 1 }
    29      c: (int){ 2 }
    30    }
    31    x: (struct){
    32    }
    33    y: (struct){
    34    }
    35    k: (_|_){
    36      // [eval] k: invalid operand e (found int, want list or struct):
    37      //     ./in.cue:7:14
    38    }
    39    e: (int){ int }
    40    comprehensionBinds: (struct){
    41      a: (struct){
    42        a: (_){ _ }
    43      }
    44      b: (struct){
    45        a: (_){ _ }
    46      }
    47    }
    48  }
    49  -- out/compile --
    50  --- in.cue
    51  {
    52    b: {
    53      for k, v in 〈1;a〉 {
    54        "\(〈1;k〉)": (〈1;v〉 + 1)
    55      }
    56    }
    57    a: {
    58      b: 1
    59      c: 2
    60    }
    61    x: {
    62      for k, v in 〈1;y〉 {
    63        "\(〈1;k〉)": 〈1;v〉
    64      }
    65    }
    66    y: {}
    67    k: {
    68      for _, v in 〈1;e〉 {
    69        〈1;v〉
    70      }
    71    }
    72    e: int
    73    comprehensionBinds: {
    74      a: {
    75        for _, _ in [
    76          1,
    77        ] {
    78          a: _
    79        }
    80      }
    81      b: {
    82        for _, _ in [
    83          1,
    84        ] {
    85          a: _
    86        }
    87      }
    88    }
    89  }