I would like to create a class that only holds single-digit numbers.
class onlyLikesSingleDigits(val anyNumber: Seq[Int]) {
val onlySingleDigits = anyNumber.filter(_ < 10)
}
The idea is you can construct it, and any numbers greater than or equal to 10 that you pass into the constructor would just be discarded.
My implementation looks rather ugly. Can't I do this without using anyNumber
? I want to initialize my class using the constructor parameters as input to the filter
, not as actual members of the class.
How can I do this with only a single val
?