From 62dfceb86ba7dfbabb0fabaf89c9cbc8d08afc32 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Tue, 12 Feb 2019 11:05:48 -0500 Subject: List.mapConcat and mapConcatM --- lib/ur/list.ur | 20 ++++++++++++++++++++ lib/ur/list.urs | 4 ++++ 2 files changed, 24 insertions(+) (limited to 'lib') diff --git a/lib/ur/list.ur b/lib/ur/list.ur index b38097b7..848bbd5f 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -101,6 +101,16 @@ fun mp [a] [b] f = mp' [] end +fun mapConcat [a] [b] f = + let + fun mapConcat' acc ls = + case ls of + [] => rev acc + | x :: ls => mapConcat' (revAppend (f x) acc) ls + in + mapConcat' [] + end + fun mapi [a] [b] f = let fun mp' n acc ls = @@ -153,6 +163,16 @@ fun mapM [m ::: (Type -> Type)] (_ : monad m) [a] [b] f = mapM' [] end +fun mapConcatM [m] (_ : monad m) [a] [b] f = + let + fun mapConcatM' acc ls = + case ls of + [] => return (rev acc) + | x :: ls' => ls <- f x; mapConcatM' (revAppend ls acc) ls' + in + mapConcatM' [] + end + fun mapMi [m ::: (Type -> Type)] (_ : monad m) [a] [b] f = let fun mapM' i acc ls = diff --git a/lib/ur/list.urs b/lib/ur/list.urs index 7e3cf205..6df2d5d9 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -20,6 +20,10 @@ val append : a ::: Type -> t a -> t a -> t a val mp : a ::: Type -> b ::: Type -> (a -> b) -> t a -> t b +val mapConcat : a ::: Type -> b ::: Type -> (a -> t b) -> t a -> t b + +val mapConcatM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type -> (a -> m (t b)) -> t a -> m (t b) + val mapPartial : a ::: Type -> b ::: Type -> (a -> option b) -> t a -> t b val mapi : a ::: Type -> b ::: Type -> (int -> a -> b) -> t a -> t b -- cgit v1.2.3