Skip to content

Instantly share code, notes, and snippets.

@theboreddev
Created November 20, 2021 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theboreddev/6d979f3cd7590310c2be7e33c7ae15bd to your computer and use it in GitHub Desktop.
Save theboreddev/6d979f3cd7590310c2be7e33c7ae15bd to your computer and use it in GitHub Desktop.
concise if
fun generatePayrollFor(employeeName: String): Either<Problem, Payroll> {
return employeeService.findEmployeeByName(employeeName)
.flatMap { employee ->
if (employee != null) buildPayrollForEmployee(employee) else UserDoesNotExistProblem(employeeName).left()
}.tapLeft {
logger.info("Could not fetch employee: ${it.message()}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment