# HG changeset patch # User Adam Chlipala # Date 1311536829 14400 # Node ID ada582d07ae1c926447a799cb7b7de3c028f9d2d # Parent 883347f5c3c20bf4c47c24f59fb87f3b03523b1c List.find diff -r 883347f5c3c2 -r ada582d07ae1 lib/ur/list.ur --- a/lib/ur/list.ur Sun Jul 24 14:49:40 2011 -0400 +++ b/lib/ur/list.ur Sun Jul 24 15:47:09 2011 -0400 @@ -206,6 +206,20 @@ fold [] end +fun find [a] f = + let + fun find' ls = + case ls of + [] => None + | x :: ls => + if f x then + Some x + else + find' ls + in + find' + end + fun search [a] [b] f = let fun search' ls = diff -r 883347f5c3c2 -r ada582d07ae1 lib/ur/list.urs --- a/lib/ur/list.urs Sun Jul 24 14:49:40 2011 -0400 +++ b/lib/ur/list.urs Sun Jul 24 15:47:09 2011 -0400 @@ -44,6 +44,8 @@ val foldlMap : a ::: Type -> b ::: Type -> c ::: Type -> (a -> b -> c * b) -> b -> t a -> t c * b +val find : a ::: Type -> (a -> bool) -> t a -> option a + val search : a ::: Type -> b ::: Type -> (a -> option b) -> t a -> option b val all : a ::: Type -> (a -> bool) -> t a -> bool