Created
September 12, 2014 10:17
-
-
Save gabro/b192a7258ec5072bd1e0 to your computer and use it in GitHub Desktop.
Beautiful validation with scalaz. Fail fast in the for-comprehension and fail slow with the application builder
This file contains 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
def editResult(testId: LabOnlineId[Test], worklistId: LabOnlineId[Worklist], result: TestResult): Future[ActionResult] = | |
for { | |
test <- ensureExists(testId)(testData.findOne(_)) | |
sample <- ensureExists(test._sampleId)(sampleData.findOneWithWorklist(_, worklistId)) | |
} yield { | |
(ensureNotClosed(sample, worklistId) |@| | |
ensureNotClosed(test, worklistId))((_,_)) match { | |
case Failure(errors) => ActionResult.UserError(errors.toList: _*) | |
case Success(_) => /* run a stored procedure */ ActionResult.Ok | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment