elm-community / list-extra

Convenience functions for working with List.
http://package.elm-lang.org/packages/elm-community/list-extra/latest
MIT License
135 stars 58 forks source link

Proposal: new function zipWith() #85

Closed frankschmitt closed 6 years ago

frankschmitt commented 6 years ago

Hello all,

I'd like to suggest an addtional function zipWith(). It should work exactly like its Haskell counterpart:

Prelude> :t zipWith
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
Prelude> zipWith (\a b -> a * b) [1, 2, 3] [10, 100, 1000]
[10,200,3000]

Implementation should be pretty straightforward - I can provide one if required (but I wanted to ask here first before submitting a pull request).

Kind regards, Frank

frankschmitt commented 6 years ago

I just noticed that lift2 seems to be exactly what I'm looking for (from the docs ):

lift2 : (a -> b -> c) -> List a -> List b -> List c

Map functions taking multiple arguments over multiple lists, regardless of list length. All possible combinations will be explored.

lift2 (+) [1,2,3][4,5] == [5,6,6,7,7,8]

Sorry for the noise, Frank

pzp1997 commented 6 years ago

I believe you are actually looking for List.map2. List.Extra.lift2 is slightly different in that it explores all of the possible pairs, sort of like a Cartesian product.

frankschmitt commented 6 years ago

You're right - List.map2 is what I was looking for, thanks.