tree-wide: use mapCartesianProduct
This commit is contained in:
parent
fe2bead78b
commit
d864c36d57
6 changed files with 33 additions and 21 deletions
|
@ -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.
|
||||
|
|
|
@ -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; }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -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" ];
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in a new issue