Hi, Playing with arrow 0.12 snapshot, I wanted to ...
# arrow
j
Hi, Playing with arrow 0.12 snapshot, I wanted to try an either computation, including one concurrent workload with
parTraverseEither
Copy code
suspend fun main() {
    val env: Env = object : Env,
        EmployeeRepository by FileEmployeeRepository("input.txt"),
        BirthdayService by BirthdayServiceInterpreter(),
        EmailService by SmtpEmailService("localhost", 8080) {}
    env.sendGreetingsUseCase(date = LocalDate.now())
}

suspend fun Env.sendGreetingsUseCase(date: LocalDate): Unit {

    val result = either<Throwable, Int> {
        val allEmployees: List<Employee> = allEmployees()()
        val greetings: List<EmailMessage> = birthdayMessages(allEmployees, date)()
        val results: List<String> = greetings.parTraverseEither(<http://Dispatchers.IO|Dispatchers.IO>) { sendGreeting(it) }()
        results.map { println(it); 1 }.sum()
    }
    result.fold({ println(it.message) }) { println("sent $it emails successfully") }
}
..the called fun for
parTraverseEither
is something like this
Copy code
interface EmailService {
    suspend fun sendGreeting(emailMessage: EmailMessage): Either<Throwable, String>
}

class SmtpEmailService(private val host: String, private val port: Int) : EmailService {

    override suspend fun sendGreeting(emailMessage: EmailMessage): Either<Throwable, String> {
        return Either.catch {
            "TODO sending ${emailMessage.subject}"
        }
    }
... but sendGreeting does not get called. I guess my usage of parTraverseEither is wrong here ? (btw, this new system of monadic bind is very nice and should be quite intuitive on the surface level)