Skip to content

Instantly share code, notes, and snippets.

@erikrozendaal
Created January 23, 2011 19:11
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 erikrozendaal/792333 to your computer and use it in GitHub Desktop.
Save erikrozendaal/792333 to your computer and use it in GitHub Desktop.
Naive option
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;
}
def negotiateFormat(request: HttpServletRequest) =
request.getParameterOption("format")
.orElse(getFormatFromUriExtension(request))
.orElse(getFormatFromAcceptHeader(request))
.getOrElse("html")
println(name.map("Hello " + _ + ", how are you?").getOrElse("Hello, how are you?"))
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