nix-book/source/nix-language/attribute-sets.adoc
Amy de Buitléir 3bda18c1db initial commit
2023-12-01 18:32:34 +00:00

34 lines
701 B
Text

= Attribute set operations
The `.` operator selects an attribute from a set.
[source]
....
nix-repl> animal = { name = { first = "Professor"; last = "Paws"; }; age = 10; species = "cat"; }
nix-repl> animal . age
10
nix-repl> animal . name . first
"Professor"
....
We can use the `?` operator to find out if a set has a particular attribute.
[source]
....
nix-repl> animal ? species
true
nix-repl> animal ? bicycle
false
....
We can use the `//` operator to modify an attribute set.
Recall that Nix values are immutable, so the result is a new value (the original is not modified).
[source]
....
nix-repl> animal // { species = "tiger"; }
{ age = 10; name = { ... }; species = "tiger"; }
....