Given that there is a functionfoo[A, B, C]( func: (a: A, b: B, c: C) => B) and I want to pass in this function def secondOfThree[A, B, C](a: A, b: B, c: C): B = b
I can call foo with foo(secondOfThree) which is ugly, but works fine.. However, I would expect to be able to call foo with something along the lines of foo(case (_, b, _) => b) however this doesn’t work.
So what’s the clean idiomatic scala way of creating a simple unnamed extracting function?
You don’t need the
casekeyword, but Scala does need to know the types:If the types are known to
foo, then the call doesn’t need to specify them: