1

In many samples of Apache Spark code we can the below code

val input = sc.hadoopFile[Text, Text, KeyValueTextInputFormat](inputFile).map{
   case (x, y) => (x.toString, y.toString)
}

Can someone please explain the use of case (x,y) here? I am aware of the use of case statement for class creation and pattern matching. However I am unable to understand the user of case (x,y in map function here.

0

1 Answer 1

2

It's just a form of function literals using pattern-matching. You could also write map { i => i match { case (x, y) => (x.toString, y.toString) } }. See Programming in Scala, "case sequences as partial functions".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.