diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2016-05-30 17:33:12 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2016-05-30 17:33:12 -0400 |
commit | a3e471e933945dcfb54873cb20c691a193b55671 (patch) | |
tree | 70ba7ffe26a589f0b97aec7016c171261c54c9e2 /lib/ur/list.ur | |
parent | 5ca6148aaf7b930a8868d0543f1a307d40532243 (diff) | |
parent | 359c1ca68f97181dada92e28440c7336fc88fff5 (diff) |
Merge branch 'upstream' into dfsg_clean20160515+dfsg
Diffstat (limited to 'lib/ur/list.ur')
-rw-r--r-- | lib/ur/list.ur | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/ur/list.ur b/lib/ur/list.ur index 11895884..50764e46 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -434,6 +434,31 @@ fun drop [a] (n : int) (xs : list a) : list a = fun splitAt [a] (n : int) (xs : list a) : list a * list a = (take n xs, drop n xs) + +fun span [a] (f : a -> bool) (ls : list a) : list a * list a = + let + fun span' ls acc = + case ls of + [] => (rev acc, []) + | x :: xs => if f x then span' xs (x :: acc) else (rev acc, ls) + in + span' ls [] + end + +fun groupBy [a] (f : a -> a -> bool) (ls : list a) : list (list a) = + let + fun groupBy' ls acc = + case ls of + [] => rev ([] :: acc) + | x :: xs => + let + val (ys, zs) = span (f x) xs + in + groupBy' zs ((x :: ys) :: acc) + end + in + groupBy' ls [] + end fun mapXiM [m ::: Type -> Type] (_ : monad m) [a] [ctx ::: {Unit}] (f : int -> a -> m (xml ctx [] [])) : t a -> m (xml ctx [] []) = let |