Given the following functions:
context(Raise<ApplicationError>)
suspend fun getUser(legalId: UserLegalId): User
context(Raise<ApplicationError>)
suspend fun getDepartment(departmentCode: DepartmentCode): Department
context(Raise<ApplicationError>)
suspend fun save(user: User): User
I want to invoke them in parallel and accumulate their errors:
context(Raise<Nel<ApplicationError>>)
override suspend fun execute(param: AddUserToDepartmentInfo): Department {
val pair: Pair<User, Department> =
parZipOrAccumulate(
{e1, e2 -> e1 + e2},
{ getUser(param.userLegalId) },
{ getDepartment(param.departmentCode) }
) { a, b -> Pair(a, b) }
saveUserDrivenPort.save(pair.first.copy(departmentId = param.departmentCode))
return pair.second
}
However, the getUser()
and getDepartment()
invocations inside parZipOrAccumulate don't compile:
No required context receiver found: Cxt { context(arrow.core.raise.Raise<xxx.ApplicationError>) private open suspend fun getUser(...)