scala - 'case' keyword appearing without its corresponding 'match' keyword -
this question has answer here:
i going through 1 scala example in 1 of popular spark books. looks strange me, @ least newbie. know how standard match/case construct in scala looks in scala. in example see 'case' being used without corresponding 'match' keyword. valid? or more of typo in book?
val joined = userdata.join(events)// rdd of (userid, (userinfo, linkinfo)) pairs val offtopicvisits = joined.filter { case (userid, (userinfo, linkinfo)) => !userinfo.topics.contains(linkinfo.topic) }.count()
so if it's not regular match/case, 'case' being used in other context?
thanks
that's called pattern matching anonymous functions in scala specification prior match
can dropped same behaviour.
{ case p1 => b1 … case pn => bn }
is equivalent to:
(x1:s1,…,xk:sk) => (x1,…,xk) match { case p1 => b1 … case pn => bn }
which in turn equivalent to:
new scala.functionk[s1,…,sk, t] { def apply(x1:s1,…,xk:sk): t = (x1,…,xk) match { case p1 => b1 … case pn => bn } }
unless expected type partial function:
new scala.partialfunction[s, t] { def apply(x: s): t = x match { case p1 => b1 … case pn => bn } def isdefinedat(x: s): boolean = { case p1 => true … case pn => true case _ => false } }
Comments
Post a Comment