* Function `findSingle' for looking up values in dictionary-like

lists.

svn path=/nixpkgs/trunk/; revision=7446
This commit is contained in:
Eelco Dolstra 2006-12-21 00:09:40 +00:00
parent fe30bcab94
commit e726057b32

View file

@ -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