summary refs log tree commit diff
path: root/doc/functions/library/attrsets.xml
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2018-10-12 16:26:56 -0400
committerGraham Christensen <graham@grahamc.com>2018-10-12 16:54:34 -0400
commit655a5fa8bf47e104a50a2e627e1cf234fff1402e (patch)
tree2fb2fe53f056ef21124e9d0c98abafe691466854 /doc/functions/library/attrsets.xml
parent4edb31882c9830d947202542a13bdb0ede17e782 (diff)
downloadnixpkgs-655a5fa8bf47e104a50a2e627e1cf234fff1402e.tar
nixpkgs-655a5fa8bf47e104a50a2e627e1cf234fff1402e.tar.gz
nixpkgs-655a5fa8bf47e104a50a2e627e1cf234fff1402e.tar.bz2
nixpkgs-655a5fa8bf47e104a50a2e627e1cf234fff1402e.tar.lz
nixpkgs-655a5fa8bf47e104a50a2e627e1cf234fff1402e.tar.xz
nixpkgs-655a5fa8bf47e104a50a2e627e1cf234fff1402e.tar.zst
nixpkgs-655a5fa8bf47e104a50a2e627e1cf234fff1402e.zip
nixpkgs docs: document zipAttrsWith
Diffstat (limited to 'doc/functions/library/attrsets.xml')
-rw-r--r--doc/functions/library/attrsets.xml79
1 files changed, 79 insertions, 0 deletions
diff --git a/doc/functions/library/attrsets.xml b/doc/functions/library/attrsets.xml
index fe44dfe4f8e..da73e02e056 100644
--- a/doc/functions/library/attrsets.xml
+++ b/doc/functions/library/attrsets.xml
@@ -1441,4 +1441,83 @@ lib.attrsets.zipAttrsWithNames
      ]]></programlisting>
   </example>
  </section>
+
+ <section xml:id="function-library-lib.attrsets.zipAttrsWith">
+  <title><function>lib.attrsets.zipAttrsWith</function></title>
+
+  <subtitle><literal>zipAttrsWith :: (String -> [ Any ] -> Any) -> [ AttrSet ] -> AttrSet</literal>
+  </subtitle>
+
+  <xi:include href="./locations.xml" xpointer="lib.attrsets.zipAttrsWith" />
+
+  <para>
+   Merge sets of attributes and use the function <varname>f</varname> to merge
+   attribute values. Similar to <xref
+   linkend="function-library-lib.attrsets.zipAttrsWithNames" /> where
+   all key names are passed for <varname>names</varname>.
+  </para>
+
+  <variablelist>
+   <varlistentry>
+    <term>
+     <varname>f</varname>
+    </term>
+    <listitem>
+     <para>
+      <literal>(String -> [ Any ] -> Any</literal>
+     </para>
+     <para>
+      Accepts an attribute name, all the values, and returns a combined value.
+     </para>
+     <variablelist>
+      <varlistentry>
+       <term>
+        <varname>name</varname>
+       </term>
+       <listitem>
+        <para>
+         The name of the attribute each value came from.
+        </para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term>
+        <varname>vs</varname>
+       </term>
+       <listitem>
+        <para>
+         A list of values collected from the list of attribute sets.
+        </para>
+       </listitem>
+      </varlistentry>
+     </variablelist>
+    </listitem>
+   </varlistentry>
+   <varlistentry>
+    <term>
+     <varname>sets</varname>
+    </term>
+    <listitem>
+     <para>
+      A list of attribute sets to zip together.
+     </para>
+    </listitem>
+   </varlistentry>
+  </variablelist>
+
+  <example xml:id="function-library-lib.attrsets.zipAttrsWith-example">
+   <title>Summing a list of attribute sets of numbers</title>
+<programlisting><![CDATA[
+lib.attrsets.zipAttrsWith
+  (name: vals: "${name} ${toString (builtins.foldl' (a: b: a + b) 0 vals)}")
+  [
+    { a = 1; b = 1; c = 1; }
+    { a = 10; }
+    { b = 100; }
+    { c = 1000; }
+  ]
+=> { a = "a 11"; b = "b 101"; c = "c 1001"; }
+     ]]></programlisting>
+  </example>
+ </section>
 </section>