在Scala中存在好几个Zip相关的函数,比如zip,zipAll,zipped 以及zipWithIndex等等.我们在代码中也经常看到这样的函数,这篇文章主要介绍一下这些函数的区别以及使用. 1.zip函数将传进来的两个参数中相应位置上的元素组成一个pair数组.如果其中一个参数元素比较长,那么多余的参数会被删掉.看下英文介绍吧: Returns a list formed from this list and another iterable collection by combining
If two Iterables aren't the same size, then zipAll can provide fillers for what it couldn't find a complement for. e.g. Iterable(x1, x2, x3) zipAll (Iterable(y1, y2), x, y) will return ((x1,y1), (x2, y2), (x3, y))):