Saturday, September 17, 2016

for Expression : Returning value using 'yield'

scala> val subjectList = List(
     |                      ("math", 70),
     |                      ("science", 60),
     |                      ("history", 80)
     |                   )
subjectList: List[(String, Int)] = List((math,70), (science,60), (history,80))

scala> //Syntax #165

scala> //for {clauses} yeild {body}

scala> val filteredList =
     |    for {
     |       info <- subjectList
     |       if info._1 != "math"
     |    }yield{
     |       info._1
     |    }
filteredList: List[String] = List(science, history)