diff options
author | Gabriel Volpe <volpegabriel@gmail.com> | 2024-04-15 19:17:53 +0200 |
---|---|---|
committer | Gabriel Volpe <volpegabriel@gmail.com> | 2024-04-15 19:17:53 +0200 |
commit | d864c36d57b46d2e5215ee67b885dd8c4fe8b764 (patch) | |
tree | ee2c2e9816c3bd56b95bc4ffcbbf400fa3f88311 /lib | |
parent | fe2bead78b1034052eca1d695118997f31826924 (diff) |
tree-wide: use mapCartesianProduct
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lists.nix | 22 |
1 files changed, 19 insertions, 3 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. |