...

Text file src/cuelang.org/go/doc/tutorial/basics/4_references/20_selectors.txtar

Documentation: cuelang.org/go/doc/tutorial/basics/4_references

     1exec cue eval selectors.cue
     2cmp stdout expect-stdout-cue
     3
     4-- frontmatter.toml --
     5title = "Accessing Fields"
     6description = ""
     7
     8-- text.md --
     9Selectors access fields within a struct using the `.` notation.
    10This only works if a field name is a valid identifier and it is not computed.
    11For other cases one can use the indexing notation.
    12
    13-- selectors.cue --
    14a: {
    15    b: 2
    16    "c-e": 5
    17}
    18v: a.b
    19w: a["c-e"]
    20
    21-- expect-stdout-cue --
    22a: {
    23    b:     2
    24    "c-e": 5
    25}
    26v: 2
    27w: 5

View as plain text