Scala - can yield be used multiple times with a for loop?
问题 An example: val l = List(1,2,3) val t = List(-1,-2,-3) Can I do something like this? for (i <- 0 to 10) yield (l(i)) yield (t(i)) Basically I want to yield multiple results for every iteration. 回答1: It's not clear what you're asking for - what you expect the semantics of multiple yield to be. One thing, though, is that you probably never want to use indexes to navigate a list - each call to t(i) is O(i) to execute. So here's one possibility that you might be asking for scala> val l = List(1,2