Skip to content

Instantly share code, notes, and snippets.

@jto
Forked from zxamplez/CODE
Last active December 14, 2015 09:38
Show Gist options
  • Save jto/5065956 to your computer and use it in GitHub Desktop.
Save jto/5065956 to your computer and use it in GitHub Desktop.
High level `Result` transformation in #playframework using #scalaz `Endo`
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2013 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
import scalaz._
import Scalaz._
import play.api.mvc._
import play.api.mvc.Results._
def setColour(c: String)(r: Result): Result = r.withCookies(Cookie("colour", c))
def notif(m: String)(r: Result): Result = r.flashing("info" -> m)
val c = (setColour("red") _).endo
val n = (notif("Your favorite colour has been saved") _).endo
(c |+| n).apply(Redirect("/"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment