I just realized we forgot to talk about zip
.
Today should be an easy one.
Don't forget, you can use Range
to create List more easily.
Easy ?
zip
allows 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 a tuple
I also introduce a little new function: swap
. It is a function available for Tuple[A, B]
. It allows to flip a tuple(a, b)
into a tuple(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 ?