export toDescList from Data.Map
Benedikt Huber
benjovi at gmx.net
Wed Sep 10 14:06:50 EDT 2008
Evan Laforge schrieb:
> So, I mentioned this a long time ago but didn't get any responses and
> then I got distracted. So this time I added a ticket and patch and
> everything: 2580
>
> Here's the text:
> It's even implemented, but not exported. Without this, there's
> apparently no way to iterate over a map from high to low, since foldl
> is also not exported.
Hi,
foldl is available via the Foldable instance for Set,Map,IntMap.
And if I'm not mistaken, a 'left fold' corresponds to 'iterate from low
to high' (try foldlM failing on the first element).
Anyway, while there is foldWithKey
> toAscList = foldWithKey (\k v m -> (k,v) : m) []
_foldrWithKey_ seems to be missing for Map/IntMap.
I don't know if there is a performance penalty using 'reverse .
toAscList' (e.g. in monadic traversals which stop after a few elements),
but I suppose you were talking about the API anyway.
Finally, I'd like to see a view on the association list, something like
> viewAssocs :: Map k v -> MapView (k,v)
> instance Foldable MapView
which would provide 'fold[lr]WithKey[M]' in a standard way.
best regards,
benedikt
More information about the Libraries
mailing list