val list1 : List[String] = List(....)
val list2 : List[String] = List(....)
val filtered = list1.filter(list2.toSet.contains)
When using the code above, will toSet be called for each item in list1 (in which case I should add another val set2 = list2.toSet, or does the Scala compiler optimizes this in which case the code above will only run toSet once?