fun IO>>.toViewModel(): IO>> = this.map { eitherContainingDomainErrorOrCandidates: Either> -> eitherContainingDomainErrorOrCandidates.map { candidates -> candidates.map { candidate -> candidate.toViewModel() } .sequence(Either.applicative()) //I think I need to use a traverse here, but this gives me an IO, Kind>>> } } suspend fun Candidate.toViewModel(): Either = Either.catch({ e -> e.message?.let { ToViewModelError(it) } ?: ToViewModelError() }) { CandidateViewModel(name, firstAttendanceAndTurns.last(), firstAttendanceAndTurns.dropLast(1)) }