doc: Add example of inherit in a let expression

This commit is contained in:
Dominic Shelton 2023-11-17 17:50:17 +11:00
parent 7ba4e073e8
commit c819375769
No known key found for this signature in database
GPG key ID: AAE070F067EC00A5

View file

@ -132,6 +132,32 @@ a = src-set.a; b = src-set.b; c = src-set.c;
when used while defining local variables in a let-expression or while
defining a set.
in a let expression, inherit can be used to selectively bring specific attributes of a set into scope. For example
```nix
let
x = { a = 1; b = 2; };
inherit (builtins) attrNames;
in
{
names = attrNames x;
}
```
is equivalent to
```nix
let
x = { a = 1; b = 2; };
in
{
names = builtins.attrNames x;
}
```
both resolve to `{ names = [ "a" "b" ]; }`.
## Functions
Functions have the following form: