Scala List zip

I just realized we forgot to talk aboutzip.

Today should be an easy one.

Don't forget, you can useRangeto create List more easily.

Easy ?

zipallows you to combine two list into one. The syntax is

List[A].zip(List[B]) => List[(A, B)]

It will return a list with both type as atuple

I also introduce a little new function:swap. It is a function available forTuple[A, B]. It allows to flip atuple(a, b)into atuple(b, a).

Extra exercise:

What happen if you zip several times in a row ?

Try out:l1.zip(l2).zip(l3).zip(l4)

And then try to combine it all with.map { case ??? => }

What will be the case pattern here ?

Reveal more information and clues
Load Exercise