| 1. |
What Is The Use Of ‘yield’ Keyword In Scala’s For-comprehension Construct? |
|
Answer» We can use ‘yield’ keyword in Scala’s for-comprehension construct. ‘for/yield’ is used to iterate a collection of elements and generates new collection of same type. It does not change the original collection. It generates new collection of same type as original collection type. For EXAMPLE, if we use ‘for/yield’ construct to iterate a List then it generates a new List only. scala> val list = List(1,2,3,4,5) We can use ‘yield’ keyword in Scala’s for-comprehension construct. ‘for/yield’ is used to iterate a collection of elements and generates new collection of same type. It does not change the original collection. It generates new collection of same type as original collection type. For example, if we use ‘for/yield’ construct to iterate a List then it generates a new List only. scala> val list = List(1,2,3,4,5) |
|