Created
January 21, 2015 15:29
-
-
Save vhazrati/a2037c34479485d2f493 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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