On 31 July 2010 06:45, wren ng thornton <w...@freegeek.org> wrote: > Ben wrote: >> >> dear traversable geniuses -- >> >> i am looking for "better" implementations of >> >> unzipMap :: M.Map a (b, c) -> (M.Map a b, M.Map a c) >> unzipMap m = (M.map fst m, M.map snd m) > > I don't think you can give a more efficient implementation using the public > interface of Data.Map. You need to have a sort of mapping function that > allows you to thread them together, either via continuations or via a > primitive:
Unless I'm missing something. This one has one traversal... unzipMap :: Ord a => M.Map a (b, c) -> (M.Map a b, M.Map a c) unzipMap = M.foldrWithKey fn (M.empty,M.empty) where fn k a (m1,m2) = (M.insert k (fst a) m1, M.insert k (snd a) m2) _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe