To answer your first question, I think you're correct about next <- moves map path.extend
I'm assuming you're talking about a "for comprehension". For example,
val a = List (1, 3, 5)
a.map(b => b * b)
//> res0: List[Int] = List(1, 9, 25)
for {
blah <- a map (b => b * b)
} yield blah
//> res1: List[Int] = List(1, 9, 25)
You can see these two return the same result and are equivalent in Scala.
So we're saying for every element in "a" call the function (b => b * b).
In your example it's more like this scenario:
case class Song(artists:List[String], title: String)
val songs = List(Song(List("Michael Jackson", "Janet Jackson"), "Scream"),
Song(List("Janet"), "Unbreakable"))
for {
song <- songs
artist <- song.artists
if artist startsWith "Mic"
} yield song.title
//> res0: List[String] = List(Scream)
songs.flatMap(
song => song.artists.withFilter(artist => artist startsWith "Mic").map(artist => song.title)
)
//> res1: List[String] = List(Scream)
You can see these are also equivalent but the "for-comprehension" is easier to read.
obj.meth(arg)to be expressed with spacesobj meth arg.