diff options
author | Graham Christensen <graham@grahamc.com> | 2018-10-12 15:42:39 -0400 |
---|---|---|
committer | Graham Christensen <graham@grahamc.com> | 2018-10-12 16:06:12 -0400 |
commit | e0c6981d19d39d41258ab626a6b9871ff0014af2 (patch) | |
tree | fb1d32eacdf456f8817ecf7e990f5cf15e8e2eef /doc/functions | |
parent | c547c3fe8262270ab8ddf129ec2bb8ebd4a38766 (diff) |
nixpkgs docs: document optionalAttrs
Diffstat (limited to 'doc/functions')
-rw-r--r-- | doc/functions/library/attrsets.xml | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/doc/functions/library/attrsets.xml b/doc/functions/library/attrsets.xml index 222b4a882917..8206142d7df2 100644 --- a/doc/functions/library/attrsets.xml +++ b/doc/functions/library/attrsets.xml @@ -1300,4 +1300,57 @@ lib.attrsets.isDerivation "foobar" </varlistentry> </variablelist> </section> + + <section xml:id="function-library-lib.attrsets.optionalAttrs"> + <title><function>lib.attrsets.optionalAttrs</function></title> + + <subtitle><literal>optionalAttrs :: Bool -> AttrSet</literal> + </subtitle> + + <xi:include href="./locations.xml" xpointer="lib.attrsets.optionalAttrs" /> + + <para> + Conditionally return an attribute set or an empty attribute set. + </para> + + <variablelist> + <varlistentry> + <term> + <varname>cond</varname> + </term> + <listitem> + <para> + Condition under which the <varname>as</varname> attribute set is + returned. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <varname>as</varname> + </term> + <listitem> + <para> + The attribute set to return if <varname>cond</varname> is true. + </para> + </listitem> + </varlistentry> + </variablelist> + + <example xml:id="function-library-lib.attrsets.optionalAttrs-example-true"> + <title>Return the provided attribute set when <varname>cond</varname> is true</title> +<programlisting><![CDATA[ +lib.attrsets.optionalAttrs true { my = "set"; } +=> { my = "set"; } + ]]></programlisting> + </example> + + <example xml:id="function-library-lib.attrsets.optionalAttrs-example-false"> + <title>Return an empty attribute set when <varname>cond</varname> is false</title> +<programlisting><![CDATA[ +lib.attrsets.optionalAttrs false { my = "set"; } +=> { } + ]]></programlisting> + </example> + </section> </section> |