From 33238a2bbf01df4b1067702edb014651d01d6c44 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 3 Oct 2007 13:26:24 +0000 Subject: [PATCH] * findSingle: return a caller-specified value if there are multiple matching elements in the list. svn path=/nixpkgs/trunk/; revision=9397 --- pkgs/lib/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix index a06090e76be..1a5dddecdfe 100644 --- a/pkgs/lib/default.nix +++ b/pkgs/lib/default.nix @@ -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;