From 9f59fb9377351d28f54174259f27ae2c23dc9dfd Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 22 Jul 2009 14:43:39 +0000 Subject: [PATCH] * findFirst is used by the LaTeX function. Forgot to commit. svn path=/nixpkgs/trunk/; revision=16438 --- pkgs/lib/lists.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/lib/lists.nix b/pkgs/lib/lists.nix index 8ac93476a53..012b95ad061 100644 --- a/pkgs/lib/lists.nix +++ b/pkgs/lib/lists.nix @@ -65,6 +65,13 @@ rec { else head found; + # Find the first element in the list matching the specified + # predicate or returns `default' if no such element exists. + findFirst = pred: default: list: + let found = filter pred list; + in if found == [] then default else head found; + + # Return true iff function `pred' returns true for at least element # of `list'. any = pred: list: