Q:

Scala - not using null in a case statement guard

I have a function 
def withEnrichment[T](f: (AccountEnrichment) => Option[T] Or ErrorMessage) = 
        (Option(xa.getEnrichment) match {
    case None => Good(None)   
    case Some(e: AccountEnrichment) => f(e)
    case _ => Bad("not an AccountEnrichment")}) 
badMap {"enrichment: " + _}

I need to add a guard to it so it ignores accounts of a certain type.  
case Some(g: AccountEnrichment) 
    if (g.getAccount ! = null && g.getAccount.getId == "BADACCOUNT") 
        => Bad("account: id cannot be BADACCOUNT")

This works, however I'd like to do it without using the null keyword.  The g.getAccount is from a Java library and can and will be null.  

A:

When a Option is applied on null it returns None.  
scala> Option(null)
res0: Option[Null] = None

this property of Option can be used instead of null comparison in your code. 
case Some(g: AccountEnrichment) 
    if (Option(g.getAccount).isEmpty && g.getAccount.getId == "BADACCOUNT") 
        => Bad("account: id cannot be BADACCOUNT")

