Skip to content

Instantly share code, notes, and snippets.

@vhazrati
Created January 21, 2015 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vhazrati/a2037c34479485d2f493 to your computer and use it in GitHub Desktop.
Save vhazrati/a2037c34479485d2f493 to your computer and use it in GitHub Desktop.
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")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment