Proposal: Add foldMapWithKey to Data.Map and Data.IntMap
ezyang
ezyang at MIT.EDU
Sat Dec 29 15:58:04 CET 2012
Note that there is relevant discussion on the pull request.
I think that a fold which reflects the underlying tree structure is not
a bad idea, but it is definitely not in-line with what the current
semantics of
Data.Map.fold are:
-- | /Deprecated./ As of version 0.5, replaced by 'L.foldr'.
--
-- /O(n)/. Fold the values in the map using the given right-associative
-- binary operator. This function is an equivalent of 'foldr' and
is present
-- for compatibility only.
fold :: (a -> b -> b) -> b -> Map k a -> b
fold = L.foldr
{-# INLINE fold #-}
...to be noted as distinct from Data.Foldable.fold, of course! So we might
need to bikeshed names. It is too bad that the intermediate structure cannot
be fused away with fold . mapWithKey!
Edward
Quoting wren ng thornton <wren at freegeek.org>:
> On 12/28/12 6:36 PM, Edward Kmett wrote:
>> I'd like to add foldMapWithKey to Data.Map and Data.IntMap.
>> [...]
>> A patch that implements the proposed operation is available here:
>>
>> https://github.com/haskell/containers/pull/24
>
> I haven't looked at the patch yet, but +1 for the addition.
>
> --
> Live well,
> ~wren
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
More information about the Libraries
mailing list