simplify Option expression

`collectFirst` is a deprecated method, I believe my suggestion is simpler.
This commit is contained in:
Anzori (Nika) Ghurtchumelia 2023-04-01 04:48:46 +04:00 committed by GitHub
parent ec83d01dca
commit aba77af6fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,10 +4,7 @@ case class UserAge(ageInYears: Option[Int]) {
def hasAge: Boolean = ageInYears.isDefined
def isGte(ageToCompare: Int): Boolean =
ageInYears
.collectFirst {
case age if age > ageToCompare => true
}.getOrElse(false)
ageInYears.exists(_ > ageToCompare)
def unapply(userAge: UserAge): Option[Int] = {
ageInYears