Created
January 4, 2017 01:36
-
-
Save cdmckay/2c0d20cbd73cffd85d08e0dee0953e72 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
templateService.getById(id) match { | |
case Found(template) => ... | |
case NotFound(message) => // message contains a nice (consistent message) | |
} | |
for { | |
checklist <- checklistService.getById(checklistId).toRight("checklist").right | |
template <- templateService.getById(checklist.template.id).toRight | |
} yield { | |
... | |
} | |
// It can also have a toOption if needed, although I'm not sure when that would be used | |
templateService.getById(id).toOption match { | |
case Some(tmpl) => | |
case None => | |
} | |
// Alternatively, we could use a helper method like toEither: | |
for { | |
checklist <- checklistService.getById(checklistId).toRight("checklist").right | |
template <- toEither(templateService.getById(checklist.template.id)) // converts to Either[String, Template] | |
} yield { | |
... | |
} | |
// I think this might be the best |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so, what are these:
checklist <- checklistService.getById(checklistId).toRight("checklist").right
? Example of an old way?