mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 23:36:16 +02:00
Merge pull request #576 from qknight/args_explanation
extended args@ explanation
This commit is contained in:
commit
5339ae4437
1 changed files with 11 additions and 5 deletions
|
@ -177,13 +177,19 @@ map (concat "foo") [ "bar" "bla" "abc" ]</programlisting>
|
||||||
<listitem><para>An <literal>@</literal>-pattern provides a means of referring
|
<listitem><para>An <literal>@</literal>-pattern provides a means of referring
|
||||||
to the whole value being matched:
|
to the whole value being matched:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting> args@{ x, y, z, ... }: z + y + x + args.a</programlisting>
|
||||||
args@{ x, y, z, ... }: z + y + x + args.a</programlisting>
|
|
||||||
|
but can also be written as:
|
||||||
|
|
||||||
|
<programlisting> { x, y, z, ... } @ args: z + y + x + args.a</programlisting>
|
||||||
|
|
||||||
Here <varname>args</varname> is bound to the entire argument, which
|
Here <varname>args</varname> is bound to the entire argument, which
|
||||||
is further matched against the pattern <literal>{ x, y, z,
|
is further matched against the pattern <literal>{ x, y, z,
|
||||||
... }</literal>.</para></listitem>
|
... }</literal>. <literal>@</literal>-pattern makes mainly sense with an
|
||||||
|
ellipsis(<literal>...</literal>) as you can access attribute names as
|
||||||
|
<literal>a</literal>, using <literal>args.a</literal>, which was given as an
|
||||||
|
additional attribute to the function.
|
||||||
|
</para></listitem>
|
||||||
|
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
|
|
||||||
|
@ -359,4 +365,4 @@ character, or inline/multi-line, enclosed within <literal>/*
|
||||||
</simplesect>
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Reference in a new issue