Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Share this Page URL
Help

Chapter 26: Extractors > 26.4 Variable argument extractors - Pg. 603

S ECTION 26.4 · Variable argument extractors The first pattern of this function matches strings that are email addresses whose user part consists of two occurrences of the same string in uppercase letters. For instance: scala> userTwiceUpper("DIDI@hotmail.com") res0: java.lang.String = match: DI in domain hotmail.com scala> userTwiceUpper("DIDO@hotmail.com") res1: java.lang.String = no match scala> userTwiceUpper("didi@hotmail.com") res2: java.lang.String = no match Note that UpperCase in function userTwiceUpper takes an empty parame- ter list. This cannot be omitted as otherwise the match would test for equality with the object UpperCase ! Note also that, even though UpperCase() itself does not bind any variables, it is still possible to associate a variable with the whole pattern matched by it. To do this, you use the standard scheme of variable binding explained in Section 15.2: the form x @ UpperCase() associates the variable x with the pattern matched by UpperCase() . For instance, in the first userTwiceUpper invocation above, x was bound to