I have a piece of code like this
def filter(t: String) : Boolean = {
var found = false;
for(s <- listofStrings) {
if ( t.contains(s)) { found = true}
}
found
}
The compiler gives a warning that its not good practise to use a mutable variable. How do I avoid this ?
Disclaimer: I used a variant of this code in an assignment and the submission is done. I would like to know what the right thing to do is
You could do:
def filter(t:String) = listofStrings.exists(t.contains(_))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With