I am not a Scala expert, and I am confused by the syntax of invoking a method with an implicit parameter.
Here is my situation:
I have a Spark RDD:
val myData: RDD[Array[String]] = ...
and determined the order for him:
object MyOrdering extends Ordering[Array[String]] = ...
I want to filter out this RDD and take the top n entries in the RDD according to my order. Spark RDD has a method for receiving the first n records with this signature:
def top(num: Int)(implicit ord: Ordering[T]): Array[T]
I originally tried this code
myData filter { D => D(9) == "yes" } top(50)(MyOrdering)
What fails with this error:
error: Int(50) does not take parameters } top(50)(MyOrdering)
However, this code works:
myData.filter(D => D(9) == "yes").top(50)(MyOrdering)
To my beginner, an example of failed code and a sample of working code look like indicating equivalent logic. Am I wrong here? Am I really doing something different in two code examples? Or is it a problem with how the Scala compiler parses the code?
source share