* 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
# predicate, or returns the default value.
findSingle = pred: default: list:
# predicate, returns `default' if no such element exists, or
# `multiple' if there are multiple matching elements.
findSingle = pred: default: multiple: list:
let found = filter pred list;
in if found == [] then default
else if tail found != [] then
abort "Multiple elements match predicate in findSingle."
else if tail found != [] then multiple
else head found;