diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2006-12-21 00:09:40 +0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2006-12-21 00:09:40 +0000 |
commit | e726057b320132c13c5f9c08fe7b864fde550533 (patch) | |
tree | 8d88dc6048b1a72c605afe71b1a7fa5f95cf26dc /pkgs | |
parent | fe30bcab941c9068e205ffe8ea29036315338371 (diff) | |
download | nixlib-e726057b320132c13c5f9c08fe7b864fde550533.tar nixlib-e726057b320132c13c5f9c08fe7b864fde550533.tar.gz nixlib-e726057b320132c13c5f9c08fe7b864fde550533.tar.bz2 nixlib-e726057b320132c13c5f9c08fe7b864fde550533.tar.lz nixlib-e726057b320132c13c5f9c08fe7b864fde550533.tar.xz nixlib-e726057b320132c13c5f9c08fe7b864fde550533.tar.zst nixlib-e726057b320132c13c5f9c08fe7b864fde550533.zip |
* Function `findSingle' for looking up values in dictionary-like
lists. svn path=/nixpkgs/trunk/; revision=7446
Diffstat (limited to 'pkgs')
-rw-r--r-- | pkgs/lib/default.nix | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix index 829f8e52a208..da279302306f 100644 --- a/pkgs/lib/default.nix +++ b/pkgs/lib/default.nix @@ -61,6 +61,16 @@ rec { fold (x: y: if pred x then [x] ++ y else y) [] list; + # Find the sole element in the list matching the specified + # predicate, or returns the default value. + findSingle = pred: default: list: + let found = filter pred list; + in if found == [] then default + else if tail found != [] then + abort "Multiple elements match predicate in findSingle." + else head found; + + # Return true if each element of a list is equal, false otherwise. eqLists = xs: ys: if xs == [] && ys == [] then true |