From d5f4669aec26c6a580a28b05a6005425ad663555 Mon Sep 17 00:00:00 2001 From: krasimir Date: Fri, 23 Oct 2009 08:35:32 +0000 Subject: experimental robust parser --- src/GF/Data/TrieMap.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/GF/Data') diff --git a/src/GF/Data/TrieMap.hs b/src/GF/Data/TrieMap.hs index 37c56fc3a..a6749d641 100644 --- a/src/GF/Data/TrieMap.hs +++ b/src/GF/Data/TrieMap.hs @@ -12,6 +12,9 @@ module GF.Data.TrieMap , insertWith , unionWith + , unionsWith + + , elems ) where import Prelude hiding (lookup, null) @@ -53,3 +56,11 @@ unionWith f (Tr mb_v1 m1) (Tr mb_v2 m2) = (Just v1,Just v2) -> Just (f v1 v2) m = Map.unionWith (unionWith f) m1 m2 in Tr mb_v m + +unionsWith :: Ord k => (v -> v -> v) -> [TrieMap k v] -> TrieMap k v +unionsWith f = foldl (unionWith f) empty + +elems :: TrieMap k v -> [v] +elems tr = collect tr [] + where + collect (Tr mb_v m) xs = maybe id (:) mb_v (Map.fold collect xs m) -- cgit v1.2.3