Skip to content

Commit 6bfcd8e

Browse files
committed
Zip operation in scala
1 parent 5bd2934 commit 6bfcd8e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Special_Functions/Zip.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Zip intertwines two collections.
3+
* Zip result will be size of shorter collection.
4+
* Zip can be performed on Lists, Sets, Maps, String, Options,Streams.
5+
**/
6+
object Zip extends App
7+
{
8+
val a = List(1,2,3,4)
9+
val b = List(5,6,7,8)
10+
println("a zip b : " + (a zip b))
11+
12+
println("(1 to 5) zip (6 to 9) : " + ((1 to 5) zip (6 to 9)))
13+
println("(1 to 2) zip (6 to 9) : " + ((1 to 2) zip (6 to 9)))
14+
}
15+
16+
/**
17+
Sample output
18+
19+
a zip b : List((1,5), (2,6), (3,7), (4,8))
20+
(1 to 5) zip (6 to 9) : Vector((1,6), (2,7), (3,8), (4,9))
21+
(1 to 2) zip (6 to 9) : Vector((1,6), (2,7))
22+
23+
**/

0 commit comments

Comments
 (0)