Skip to content

Commit

Permalink
tree-wide: use mapCartesianProduct
Browse files Browse the repository at this point in the history
  • Loading branch information
gvolpe committed Apr 15, 2024
1 parent fe2bead commit d864c36
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
22 changes: 19 additions & 3 deletions lib/lists.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/services/x11/display-managers/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -312,7 +312,7 @@ in
providedSessions = [ sessionName ];
})
)
(cartesianProductOfSets { dm = dms; wm = wms; })
{ dm = dms; wm = wms; }
);
};

Expand Down
15 changes: 7 additions & 8 deletions pkgs/by-name/so/solo5/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];
};
};

}
7 changes: 3 additions & 4 deletions pkgs/data/fonts/junicode/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions pkgs/data/icons/catppuccin-cursors/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 1 addition & 2 deletions pkgs/data/icons/comixcursors/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit d864c36

Please sign in to comment.