Reputation: 2582
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?
Upvotes: 16
Views: 2469
Reputation: 8932
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.
Upvotes: 18