Sort of. flatMap
quite explicitly passes an argument to its own argument. This is the nature of a higher-order function -- you basically give it a callback, it calls the callback, and then it does something with the result. The only implicit thing happening is conversion of a method to a function type.
Any method can be converted to an equivalent function type. So def recursiveListFiles(f: File): Array[File]
is equivalent to File => Array[File]
, which is great, because on an Array[File]
, you have flatMap[B](f: File => Array[B]): Array[B]
, and your method's function type fits perfectly: the type parameter B
is chosen to be File
.
As mentioned in another answer, you could explicitly create that function by doing:
these.filter(_.isDirectory).flatMap(file => recursiveListFiles(file))
or
these.filter(_.isDirectory).flatMap(recursiveListFiles(_))
or
these.filter(_.isDirectory).flatMap(recursiveListFiles _)
In more complex circumstances, you might need to work with one of those more verbose options, but in your case, no need to bother.