For the record, you can make this a little more general without restricting yourself to line characters and a little more functional (in my opinion), switching the order of the arguments and using two lists of arguments. Here's how I write it:
def isCorrect[A](allowed: Set[A])(s: Seq[A]) = s forall allowed
Now you can consider this method as a function and "partially apply" it to create more specialized functions:
val isDigits = isCorrect("0123456789".toSet) _ val isAs = isCorrect(Set('A')) _
Which allows you to do the following:
scala> isDigits("218903") res1: Boolean = true scala> isAs("218903") res2: Boolean = false scala> isDigits("AAAAAAA") res3: Boolean = false scala> isAs("AAAAAAA") res4: Boolean = true
Or you can just use something like isCorrect("abcdr".toSet)("abracadabra") .
source share