Skip to content

Instantly share code, notes, and snippets.

@aembleton
Created November 18, 2013 09:27
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 aembleton/7525073 to your computer and use it in GitHub Desktop.
Save aembleton/7525073 to your computer and use it in GitHub Desktop.
Util for Play Cookies
package util
import play.api.mvc.{Cookie, Cookies}
/**
* Created with IntelliJ IDEA.
* User: arthur
* Date: 17/11/13
* Time: 22:26
* To change this template use File | Settings | File Templates.
*/
object CookiesUtil {
implicit class CookiesImprovements(val c: Cookies) {
import util.StringUtils._
def getAsIntOrElse(key: String, default: Int): Int = c match {
case x: Cookies => x.get(key) match {
case cookieOpt: Some[Cookie] => cookieOpt.get match {
case cookie: Cookie => cookie.value.toIntOrElse(default)
case _ => default
}
case _ => default
}
case _ => default
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment