`myEither.fold({ IO.unit }, { IO.effect { susFun()...
# arrow
p
myEither.fold({ IO.unit }, { IO.effect { susFun() } }).bind()
k
Kinda feels wrong đŸ˜„ (not using IO because it's suspend and I only have IO.fx in the routes. Is that the correct approach?
Copy code
override suspend fun authenticate(request: Tuple2<Password, Email>): Either<String, AuthenticatedUser> {
        val (providedPassword, email) = request
        val findUser: Either<String, User> = userRepository.findUserByEmail(email)
        return findUser.fold(
            ifLeft = { it.left() },
            ifRight = { dbUser ->
                val hashedPw = hashPw(providedPassword, email)
                if (dbUser.email.value == email.value && dbUser.password?.value?.contentEquals(hashedPw.payload) == true) {
                    val toUpdate = dbUser.copy(lastLogin = ZonedDateTime.now())
                    return userRepository.updateUser(toUpdate)
                        .map { AuthenticatedUser(it, null) }
                } else {
                    Either.left("Invalid credentials.")
                }
            }
        )
    }
p
== true
is unnecessary (pet peeve)
the return…is it local or non-local?
I would keep it local if possible
so…delete the keyword
return
from
return userRepository.updateUser
otherwise ye
I would move ifRight to its own function
(if I can find where dbUser comes from, I guess from the class)
k
Thanks, that sounds good đŸ™‚ dbUser is the right result of val findUser: Either<String, User> = userRepository.findUserByEmail(email)? Or what do you mean? ^^
Oops, yeah thanks it was actuallya non-local return.. Kinda forget sometimes when switching from Java to Kotlin that I shouldn't return inside a lambda.
But the
== true
is necessary because it's a nullable boolean, or am I missing something?
p
nullable boolean oooh right
k
is there some sort of functional approach for a eventbus? And also available in arrow? đŸ˜„
p
yeah, use
Queue
queue + sealed classes you have MVI
k
is there a doc for Queue?
ah found it, thank you