1

This might have been asked before, but I would like to understand why you must use the { syntax for filters or maps using pattern matching,

val arr = Array((1,1), (1,2), (1,5), (2,6), (2,7), (2,3), (3,8), (3,4))

arr.filter(x => x._1 == 1) // works
arr.filter(case(x,y) => x == 1) // doesn't work
arr.filter{case(x,y) => x ==1} //works

Why does the second filter expression not work? Is there a design consideration, since for a person new to the language, understanding that you must use curly brackets instead of regular ones for a special type of filter is hard to figure out or remember.

Allen Wang
  • 2,426
  • 2
  • 24
  • 48
  • 2
    check this one http://stackoverflow.com/questions/4386127/what-is-the-formal-difference-in-scala-between-braces-and-parentheses-and-when – Gustek Nov 11 '16 at 16:34
  • The slightly improved question is why not `arr.filter((x,y) => true)`. – som-snytt Nov 11 '16 at 20:56

0 Answers0