0 votes
in Scala Constructs by
Can you explain the functionality of Yield?

1 Answer

0 votes
by

Scala uses the yield keyword in conjunction with the for loop. Following the completion of loop iterations, the yield keyword returns the result. For loops internally store the iterated result in a buffer, and upon finishing all iterations, it yields the final result from that buffer. Maps, FlatMaps, Filters, and Nomads are all supported by Yield. 

Syntax:

var result = for{condition}  

yield variable 

...