Mercurial > urweb
changeset 1519:ada582d07ae1
List.find
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 24 Jul 2011 15:47:09 -0400 |
parents | 883347f5c3c2 |
children | b5517f47b1f1 |
files | lib/ur/list.ur lib/ur/list.urs |
diffstat | 2 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 =
--- 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