Add traverseWithIndex to Data.Sequence

Milan Straka milan at
Tue Jan 19 17:24:00 UTC 2016

Hi David and all,

> -----Original message-----
> From: David Feuer <david.feuer at>
> Sent: 19 Jan 2016, 11:55
> Indexed traversals seem to be pretty popular these days, and sequences
> should be able to support them efficiently. At present, the best
> options are
> 1. Thread a counter through. This doesn't work well for weird things
> like lazy State.
> 2. Use zipWith first to add indices, then traverse. This adds a
> smaller, but still asymptotic, penalty to the same sorts of unusual
> functors, and also adds constant-factor overhead to strict ones that
> the counter threading wouldn't.
> I propose the following, modified mechanically from mapWithIndex. It
> should be about as efficient as possible in all cases.

+1 from me.

BTW, we have traverseWithKey in Map and IntMap, and traverseWithIndex
seems a bit analogous for (indexable) Sequences, where an index can play
a role of a key.


More information about the Libraries mailing list