Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine 2 Iterators in Scala?

a and b are values of Iterator[String] type. I need c to include all the elements of a and b. Surprisingly I can't figure out how to achieve this. May you happen to know?

like image 338
Ivan Avatar asked Jan 28 '12 19:01

Ivan


1 Answers

++ operator will do that work.
An example:

scala> val a = "abcd".combinations(2)
//a: Iterator[String] = non-empty iterator

scala> val b = "efg".combinations(2)
//b: Iterator[String] = non-empty iterator

scala> val c = a++b
//c: Iterator[String] = non-empty iterator

scala> c.toList
//res0: List[String] = List(ab, ac, ad, bc, bd, cd, ef, eg, fg)
like image 134
om-nom-nom Avatar answered Sep 28 '22 17:09

om-nom-nom