* findSingle: return a caller-specified value if there are multiple

matching elements in the list.

svn path=/nixpkgs/trunk/; revision=9397
This commit is contained in:
Eelco Dolstra 2007-10-03 13:26:24 +00:00
parent 459b386ff9
commit 33238a2bbf

View File

@ -76,12 +76,12 @@ rec {
# Find the sole element in the list matching the specified # Find the sole element in the list matching the specified
# predicate, or returns the default value. # predicate, returns `default' if no such element exists, or
findSingle = pred: default: list: # `multiple' if there are multiple matching elements.
findSingle = pred: default: multiple: list:
let found = filter pred list; let found = filter pred list;
in if found == [] then default in if found == [] then default
else if tail found != [] then else if tail found != [] then multiple
abort "Multiple elements match predicate in findSingle."
else head found; else head found;