Created
January 23, 2011 19:11
-
-
Save erikrozendaal/792333 to your computer and use it in GitHub Desktop.
Naive option
This file contains 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
public String negotiateFormat(HttpServletRequest request) { | |
String format = request.getParameter("format"); | |
if (format == null) | |
format = getFormatFromUriExtension(request); | |
if (format == null) | |
format = getFormatFromAcceptHeader(request); | |
if (format == null) | |
format = "html"; | |
return format; | |
} |
This file contains 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
def negotiateFormat(request: HttpServletRequest) = | |
request.getParameterOption("format") | |
.orElse(getFormatFromUriExtension(request)) | |
.orElse(getFormatFromAcceptHeader(request)) | |
.getOrElse("html") |
This file contains 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
println(name.map("Hello " + _ + ", how are you?").getOrElse("Hello, how are you?")) |
This file contains 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
val name: Option[String] = Some("Erik") | |
if (name.isDefined) // if (name != null) in Java | |
println("Hello " + name.get + ", how are you?") | |
else | |
println("Hello, how are you?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment