16

With this code

val foo = List('a', 'b', 'c')
aString.forall(foo.contains(_))

IntelliJ highlights foo.contains(_) and suggests "Anonymous function convertible to method value". I have researched eta expansion, but am unable to see how I could improve this particular piece of code. Any ideas?

Lasf
  • 2,536
  • 1
  • 16
  • 35

1 Answers1

18

I believe it's saying that you could simply have

val foo = List('a', 'b', 'c')
aString.forall(foo.contains)

Note that we're not explicitly converting the foo.contains method here to an anonymous function.

Hugh
  • 8,872
  • 2
  • 37
  • 42