From the first time I read that:
for {
harpo<-list1 if harpo.length>0
groucho<-list2
chico<-list3
} yield (harpo, groucho, chico)
translates to:
list1.filter(_.length>0).flatMap(harpo =>
list2.flatMap(groucho=>list3.map((harpo,groucho,_)))
)
I was worried about unnecessary intermediate collections returned by filter
, flatMap
& map
. The first was fixed in Scala 2.8(?) by addition of the withFilter
method, and I suspect that there's some magic going on which changes the return type of these methods depending on usage so when used as a parameter to flatMap
they return a non-strict collection, but I can't find any proof. Are my suspicions right and it isn't as ineffective as it seems by first glance?