Does scala perform optimisations in chained functions?

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?



Read more here: https://stackoverflow.com/questions/65715929/does-scala-perform-optimisations-in-chained-functions

Content Attribution

This content was originally published by theDude at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: