Skip to content

Instantly share code, notes, and snippets.

Created October 27, 2021 06:21
What would you like to do?
Using fold method
class PayrollService(private val employeeService: EmployeeService) {
private val logger = LoggerFactory.getLogger(
fun generatePayrollFor(employeeName: String): Either<Problem, Payroll> {
return employeeService.findEmployeeByName(employeeName)
{ httpFailureProblem ->"Could not fetch employee: ${httpFailureProblem.message()}")
{ employee ->
data class Payroll(private val id: String,
private val employeeId: String,
private val salary: Float,
private val date: Date)
private fun buildPayrollForEmployee(employee: Employee): Either<Problem, Payroll> {
return Payroll(UUID.randomUUID().toString(),, employee.salary, Date()).right()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment