Zippety zip

In Haskell there is a zipWith operator which works as follows:

This is a nice way to combine two lists. So why doesn’t Scala have it? Consider the following implementation:

running it yields:

Well, this is almost the same as what we had in Haskell, although it’s not part of the standard api. One problem with this is that it is not very Scala-like. The function zipWith doesn’t fit well inside the object oriented paradigm because there is no apparent object to call it on. This is also the reason for the prefix notation which is very rare in Scala due to the object oriented design of the standard api.
To do it in a more scala-like way we can do as follows:

Now we can do it in the scala way:



Leave a Reply

Your email address will not be published. Required fields are marked *