diff options
author | Adam Chlipala <adam@chlipala.net> | 2018-04-14 15:15:07 -0400 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2018-04-14 15:15:07 -0400 |
commit | 0cadb1a719bc515af2449ac966e545a6599aee4d (patch) | |
tree | a350817dec17293fa409151d868ec6a4f87f3a8c | |
parent | 1fef19035d2f3388e9ab0dad1889a4cad5c1ca3e (diff) |
List.findM
-rw-r--r-- | lib/ur/list.ur | 15 | ||||
-rw-r--r-- | lib/ur/list.urs | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/ur/list.ur b/lib/ur/list.ur index a7296552..95d6fbc8 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -255,6 +255,21 @@ fun find [a] f = find' end +fun findM [m] (_ : monad m) [a] f = + let + fun find' ls = + case ls of + [] => return None + | x :: ls => + b <- f x; + if b then + return (Some x) + else + find' ls + in + find' + end + fun search [a] [b] f = let fun search' ls = diff --git a/lib/ur/list.urs b/lib/ur/list.urs index 37cbe442..fe730152 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -60,6 +60,8 @@ val mem : a ::: Type -> eq a -> a -> t a -> bool val find : a ::: Type -> (a -> bool) -> t a -> option a +val findM : m ::: (Type -> Type) -> monad m -> a ::: Type -> (a -> m bool) -> t a -> m (option a) + val search : a ::: Type -> b ::: Type -> (a -> option b) -> t a -> option b val all : a ::: Type -> (a -> bool) -> t a -> bool |