Re:Escape from Callback Hell: Callbacks are the modern goto
by saryant on Friday November 02, 2012 @02:58PM
(#4734203)
Similar to this is the Scala fold convention.
An example from the Play! Framework for form submissions:
def submit = Action { implicit request =>
contactForm.bindFromRequest.fold(
errors => BadRequest(html.contact.form(errors)),
contact => Ok(html.contact.summary(contact))
)
}
It allows you to write code like this:
Whenever one of the functions above returns an error, the whole expression is that error. The outcome is either an error (if there was any) or the end value of Set[User]. No need to manually handle an error until you get to the end result.