mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-16 23:27:17 +02:00
doc: Add example of inherit in a let expression
This commit is contained in:
parent
7ba4e073e8
commit
c819375769
1 changed files with 40 additions and 14 deletions
|
@ -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
|
when used while defining local variables in a let-expression or while
|
||||||
defining a set.
|
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
|
||||||
|
|
||||||
Functions have the following form:
|
Functions have the following form:
|
||||||
|
|
Loading…
Add table
Reference in a new issue