tree-wide: use mapCartesianProduct

This commit is contained in:
Gabriel Volpe 2024-04-15 19:17:53 +02:00
parent fe2bead78b
commit d864c36d57
No known key found for this signature in database
GPG Key ID: 121D4302A64B2261
6 changed files with 33 additions and 21 deletions

View File

@ -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.

View File

@ -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; }
);
};

View File

@ -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" ];
};
};
}

View File

@ -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 {

View File

@ -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";

View File

@ -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";