summary refs log tree commit diff
path: root/lib/lists.nix
diff options
context:
space:
mode:
authorFelix Buehler <account@buehler.rocks>2023-06-25 13:16:06 +0200
committerFelix Buehler <account@buehler.rocks>2023-11-14 19:52:32 +0100
commit66261e9961254a5c8a7c096e091fd42deb988cee (patch)
tree2ce363704f034762ffb7a96d5d3c9a152514a5d8 /lib/lists.nix
parentb5bd1053d2b02040f8e6f628bbe213358dbe3bfc (diff)
downloadnixpkgs-66261e9961254a5c8a7c096e091fd42deb988cee.tar
nixpkgs-66261e9961254a5c8a7c096e091fd42deb988cee.tar.gz
nixpkgs-66261e9961254a5c8a7c096e091fd42deb988cee.tar.bz2
nixpkgs-66261e9961254a5c8a7c096e091fd42deb988cee.tar.lz
nixpkgs-66261e9961254a5c8a7c096e091fd42deb988cee.tar.xz
nixpkgs-66261e9961254a5c8a7c096e091fd42deb988cee.tar.zst
nixpkgs-66261e9961254a5c8a7c096e091fd42deb988cee.zip
lib.lists.allUnique: init
Diffstat (limited to 'lib/lists.nix')
-rw-r--r--lib/lists.nix13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/lists.nix b/lib/lists.nix
index 3835e3ba69c..15047f488f4 100644
--- a/lib/lists.nix
+++ b/lib/lists.nix
@@ -821,6 +821,19 @@ rec {
    */
   unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [];
 
+  /* Check if list contains only unique elements. O(n^2) complexity.
+
+     Type: allUnique :: [a] -> bool
+
+     Example:
+       allUnique [ 3 2 3 4 ]
+       => false
+       allUnique [ 3 2 4 1 ]
+       => true
+   */
+  allUnique = list: (length (unique list) == length list);
+
+
   /* Intersects list 'e' and another list. O(nm) complexity.
 
      Example: