mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-11 04:02:55 +03:00
* 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:
parent
459b386ff9
commit
33238a2bbf
@ -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;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user