Scala yield
先看下在Programming scala里yield的定义:
For each iteration of your for loop, yield generates a value which will be remembered. It's like the for loop has a buffer you can't see, and for each iteration of your for loop, another item is added to that buffer. When your for loop finishes running, it will return this collection of all the yielded values. The type of the collection that is returned is the same type that you were iterating over, so a Map yields a Map, a List yields a List, and so on.
Also, note that the initial collection is not changed; the for/yield construct creates a new collection according to the algorithm you specify.
大致意思是,每次for循环,yield都会生成一个会被记住的值。就像在循环的时候有一个无形的Buffer,每次迭代,另一个元素就会放入到Buffer里。 <