Skip to content

Commit

Permalink
add example to crossLists deprecation message
Browse files Browse the repository at this point in the history
  • Loading branch information
gvolpe committed Mar 27, 2024
1 parent 1e77fc4 commit f4c392c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/lists.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ rec {
=> [ "13" "14" "23" "24" ]
```
To migrate to `lib.mapCartesianProduct` we need to pass an attrset as input instead of a list:
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]; }
Expand All @@ -1701,7 +1701,18 @@ rec {
:::
*/
crossLists = warn
"lib.crossLists is deprecated, use lib.mapCartesianProduct instead."
''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]);

/**
Expand Down

0 comments on commit f4c392c

Please sign in to comment.