Is there a two-operand equivalent to map built into Haskell with a type signature of:
map2 :: (a -> b -> c) -> [a] -> [b] -> [c]
The following equivalence should hold:
map2 operator as bs === [operator a b | (a, b) <- zip as bs]
Example:
ghci> map2 (*) [2,3] [4,5]
[8,15]
The function zipWith does what you need. There are also zipWith3 .. zipWith7 for cases with more than two lists.
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