Michael
04/18/2018, 1:42 PMOptionals
when you need to hang on to intermediate values? (“Promise Hell” in JavaScript) Sample: return receiptRepository.findOne(receiptId)
.map { lineRepository.findOne(it, lineId) }
.map { lineRepository.update( /* need receipt here */, it, updatedLine) }
.map { ResponseEntity(it, HttpStatus.OK ) }
.orElse { ResponseEntity(HttpStatus.NOT_FOUND) }
Andreas Sinz
04/18/2018, 1:44 PM.map { lineRepository.findOne(it, lineId) to it }
?Andreas Sinz
04/18/2018, 1:48 PM.map {
val line = lineRepository.findOne(it, lineId)
lineRepository.update(it, line, updatedLine)
}
Michael
04/18/2018, 1:49 PMmarstran
04/18/2018, 1:51 PMval response = for {
receipt <- receiptRepository.findOne(receiptId)
line <- lineRepository,findOne(receipt, lineId)
lineUpdate <- lineRepository.update(receipt, line, updatedLine)
} yield ResponseEntity(lineUpdate, HttpStatus.OK)
return response.orElse { ResponseEntity(HttpStatus.NOT_FOUND) }
Michael
04/18/2018, 1:55 PMgildor
04/18/2018, 2:23 PMbindings
that allow to write such code much easier