I often find myself looking to use a function like:
zipWithMap :: (a -> b) -> [a] -> [(a, b)]
zipWithMap f xs = zip xs $ map f xs
Such that:
zipWithMap (+3) [1..4] = [(1, 4), (2, 5), (3, 6), (4, 7)]
I find myself looking for this so often, in fact, that I fear I am either reinventing the wheel or using an idiom so poorly-suited to Haskell that Real Programmers have moved away from it, thus its exclusion from stdlib.
Hoogle gives me nothing with that type signature, so I'm forced to ask: is there a more idiomatic approach? Perhaps with Arrows?
zipWithMap f = map $ id &&& f
though I'm not sure that's any better than the (subjectively) simpler style above.
Also:
Data.Tuple.Extra> map (second (+3) . dupe) [1..4]
[(1,4),(2,5),(3,6),(4,7)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With