Let's say I have some v
, which is both Applicative
and also Traversable
. How can I get a v
with the indices of v
? For a concrete example, consider V3
from Linear
. I want V3 0 1 2
.
One way is to use mapAccumL
with a dummy, for example:
snd $ T.mapAccumL
(\idx _ -> (idx + 1, idx))
0 (pure "") :: V3 Int
But the (pure "")
dummy feels inelegant. How can we do this in a more elegant way?