object play { println("Welcome to the Scala worksheet") case class User(id:Int, name:String) def getUser:User = null def processUser(u:User):String= u.name Option(getUser) Option(getUser).fold("Sky")(u=>processUser(u)) object SValue { def apply[T, P <: Any](a: T, f: T => P)(implicit defaultValue: P) = Option(a).fold(defaultValue)(f) } SValue(getUser,processUser)("Sky") }