I'm trying to write the following function without using var and only val. Any ideas how to approach this ?
def isValidBSONId(id: String): Boolean = {
var valid: Boolean = false
import reactivemongo.bson.utils.Converters._
try {
str2Hex(id)
valid = true
} catch {
case _ => valid = false
}
valid
}
Just Try{}.isSuccess
def isValidBSONId(id: String): Boolean = {
import reactivemongo.bson.utils.Converters._
Try(str2Hex(id)).isSuccess
}
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