about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGabriel Volpe <volpegabriel@gmail.com>2024-04-15 19:17:53 +0200
committerGabriel Volpe <volpegabriel@gmail.com>2024-04-15 19:17:53 +0200
commitd864c36d57b46d2e5215ee67b885dd8c4fe8b764 (patch)
treeee2c2e9816c3bd56b95bc4ffcbbf400fa3f88311
parentfe2bead78b1034052eca1d695118997f31826924 (diff)
downloadnixlib-d864c36d57b46d2e5215ee67b885dd8c4fe8b764.tar
nixlib-d864c36d57b46d2e5215ee67b885dd8c4fe8b764.tar.gz
nixlib-d864c36d57b46d2e5215ee67b885dd8c4fe8b764.tar.bz2
nixlib-d864c36d57b46d2e5215ee67b885dd8c4fe8b764.tar.lz
nixlib-d864c36d57b46d2e5215ee67b885dd8c4fe8b764.tar.xz
nixlib-d864c36d57b46d2e5215ee67b885dd8c4fe8b764.tar.zst
nixlib-d864c36d57b46d2e5215ee67b885dd8c4fe8b764.zip
tree-wide: use mapCartesianProduct
-rw-r--r--lib/lists.nix22
-rw-r--r--nixos/modules/services/x11/display-managers/default.nix4
-rw-r--r--pkgs/by-name/so/solo5/package.nix15
-rw-r--r--pkgs/data/fonts/junicode/tests.nix7
-rw-r--r--pkgs/data/icons/catppuccin-cursors/default.nix3
-rw-r--r--pkgs/data/icons/comixcursors/default.nix3
6 files changed, 33 insertions, 21 deletions
diff --git a/lib/lists.nix b/lib/lists.nix
index c162f921280d..28fa277b22b1 100644
--- a/lib/lists.nix
+++ b/lib/lists.nix
@@ -1688,16 +1688,32 @@ rec {
     ## `lib.lists.crossLists` usage example
 
     ```nix
-    crossLists (x:y: "${toString x}${toString y}") [[1 2] [3 4]]
+    crossLists (x: y: "${toString x}${toString y}") [[1 2] [3 4]]
     => [ "13" "14" "23" "24" ]
     ```
 
+    The following function call is equivalent to the one deprecated above:
+
+    ```nix
+    mapCartesianProduct (x: "${toString x.a}${toString x.b}") { a = [1 2]; b = [3 4]; }
+    => [ "13" "14" "23" "24" ]
+    ```
     :::
   */
   crossLists = warn
-    "lib.crossLists is deprecated, use lib.cartesianProductOfSets instead."
-    (f: foldl (fs: args: concatMap (f: map f args) fs) [f]);
+    ''lib.crossLists is deprecated, use lib.mapCartesianProduct instead.
 
+    For example, the following function call:
+
+    nix-repl> lib.crossLists (x: y: x+y) [[1 2] [3 4]]
+    [ 4 5 5 6 ]
+
+    Can now be replaced by the following one:
+
+    nix-repl> lib.mapCartesianProduct ({x,y}: x+y) { x = [1 2]; y = [3 4]; }
+    [ 4 5 5 6 ]
+    ''
+    (f: foldl (fs: args: concatMap (f: map f args) fs) [f]);
 
   /**
     Remove duplicate elements from the `list`. O(n^2) complexity.
diff --git a/nixos/modules/services/x11/display-managers/default.nix b/nixos/modules/services/x11/display-managers/default.nix
index 4c62e964c34c..0f9b712c6df5 100644
--- a/nixos/modules/services/x11/display-managers/default.nix
+++ b/nixos/modules/services/x11/display-managers/default.nix
@@ -284,7 +284,7 @@ in
       in
         # We will generate every possible pair of WM and DM.
         concatLists (
-            builtins.map
+            lib.mapCartesianProduct
             ({dm, wm}: let
               sessionName = "${dm.name}${optionalString (wm.name != "none") ("+" + wm.name)}";
               script = xsession dm wm;
@@ -312,7 +312,7 @@ in
                   providedSessions = [ sessionName ];
                 })
             )
-            (cartesianProductOfSets { dm = dms; wm = wms; })
+            { dm = dms; wm = wms; }
           );
   };
 
diff --git a/pkgs/by-name/so/solo5/package.nix b/pkgs/by-name/so/solo5/package.nix
index 240c69a40a0f..57ccd1e24b2b 100644
--- a/pkgs/by-name/so/solo5/package.nix
+++ b/pkgs/by-name/so/solo5/package.nix
@@ -63,16 +63,15 @@ in stdenv.mkDerivation {
     runHook postCheck
   '';
 
-  meta = {
+  meta = with lib; {
     description = "Sandboxed execution environment";
     homepage = "https://github.com/solo5/solo5";
-    license = lib.licenses.isc;
-    maintainers = with lib.maintainers; [ ehmry ];
-    platforms = builtins.map ({arch, os}: "${arch}-${os}")
-      (lib.cartesianProductOfSets {
-        arch = [ "aarch64" "x86_64" ];
-        os = [ "freebsd" "genode" "linux" "openbsd" ];
-      });
+    license = licenses.isc;
+    maintainers = [ maintainers.ehmry ];
+    platforms = mapCartesianProduct ({ arch, os }: "${arch}-${os}") {
+      arch = [ "aarch64" "x86_64" ];
+      os = [ "freebsd" "genode" "linux" "openbsd" ];
+    };
   };
 
 }
diff --git a/pkgs/data/fonts/junicode/tests.nix b/pkgs/data/fonts/junicode/tests.nix
index fda7de31670e..831e60796d12 100644
--- a/pkgs/data/fonts/junicode/tests.nix
+++ b/pkgs/data/fonts/junicode/tests.nix
@@ -15,14 +15,13 @@ let
       '');
 in
 builtins.listToAttrs (
-  map
-    texTest
-    (lib.attrsets.cartesianProductOfSets {
+  lib.mapCartesianProduct texTest
+    {
       tex = [ "xelatex" "lualatex" ];
       fonttype = [ "ttf" "otf" ];
       package = [ "junicode" ];
       file = [ ./test.tex ];
-    })
+    }
   ++
   [
     (texTest {
diff --git a/pkgs/data/icons/catppuccin-cursors/default.nix b/pkgs/data/icons/catppuccin-cursors/default.nix
index 20e4718515e6..eeb9dd3227f0 100644
--- a/pkgs/data/icons/catppuccin-cursors/default.nix
+++ b/pkgs/data/icons/catppuccin-cursors/default.nix
@@ -9,9 +9,8 @@ let
     palette = [ "Frappe" "Latte" "Macchiato" "Mocha" ];
     color = [ "Blue" "Dark" "Flamingo" "Green" "Lavender" "Light" "Maroon" "Mauve" "Peach" "Pink" "Red" "Rosewater" "Sapphire" "Sky" "Teal" "Yellow" ];
   };
-  product = lib.attrsets.cartesianProductOfSets dimensions;
   variantName = { palette, color }: (lib.strings.toLower palette) + color;
-  variants = map variantName product;
+  variants = lib.mapCartesianProduct variantName dimensions;
 in
 stdenvNoCC.mkDerivation rec {
   pname = "catppuccin-cursors";
diff --git a/pkgs/data/icons/comixcursors/default.nix b/pkgs/data/icons/comixcursors/default.nix
index 1c4fdc195180..735ff686b49c 100644
--- a/pkgs/data/icons/comixcursors/default.nix
+++ b/pkgs/data/icons/comixcursors/default.nix
@@ -7,14 +7,13 @@ let
     thickness = [ "" "Slim_" ];  # Thick or slim edges.
     handedness = [ "" "LH_" ];   # Right- or left-handed.
   };
-  product = lib.cartesianProductOfSets dimensions;
   variantName =
     { color, opacity, thickness, handedness }:
     "${handedness}${opacity}${thickness}${color}";
   variants =
     # (The order of this list is already good looking enough to show in the
     # meta.longDescription.)
-    map variantName product;
+    lib.mapCartesianProduct variantName dimensions;
 in
 stdenvNoCC.mkDerivation rec {
   pname = "comixcursors";