Proposal: add foldMapWithIndex to Data.Sequence

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Proposal: add foldMapWithIndex to Data.Sequence

David Feuer

foldMapWithIndex :: Monoid m
     => (Int -> a -> m) -> Seq a -> m

This would match both Data.Map.foldMapWithKey and Control.Lens.Indexed.ifoldMap, filling out the indexed fold menagerie.

Annoyingly, the straightforward implementation I've come up with is rather slow when used with Endo to implement either foldlWithIndex or foldrWithIndex. I suspect the polymorphic recursion inherent in these sequences is blinding GHC's optimizer. Oh well.


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: add foldMapWithIndex to Data.Sequence

Bardur Arantsson-2
On 05/20/2016 07:20 PM, David Feuer wrote:
> foldMapWithIndex :: Monoid m
>      => (Int -> a -> m) -> Seq a -> m
>
> This would match both Data.Map.foldMapWithKey and
> Control.Lens.Indexed.ifoldMap, filling out the indexed fold menagerie.
>

+1

on the general principle that having as uniform an interface to the
'collections' is a Good Thing.


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries