Bob Glamm
04/27/2020, 7:19 PMOption.fold[F, T, S](ifNone: => F[S], block: T => F[S])
?Bob Glamm
04/27/2020, 7:22 PMsuspend () -> T
vs. IO<T>
Bob Glamm
04/27/2020, 7:24 PMsuspend () -> T
, how do I know which F
is used in its isomorphism in Kind<ForF, T>
?simon.vergauwen
04/28/2020, 10:29 AMpakoito
04/28/2020, 10:36 AMYET▾
vjames19
04/29/2020, 10:11 PMimport arrow.core.Either
// fictitious domain
sealed class BusinessLogic1Error {
// all errors
}
sealed class BusinessLogic2Error {
// all errors
}
sealed class BusinessLogic3Error {
// all errors
}
fun businessLogic1(): Either<BusinessLogic1Error, String> = TODO()
fun businessLogic2(): Either<BusinessLogic2Error, String> = TODO()
fun businessLogic3(): Either<BusinessLogic3Error, String> = TODO()
// use cases that use different business logic
// approach 1
// Union Type through wrapper class
sealed class UseCaseError {
class BusinessLogic1(val businessLogic1Error: BusinessLogic1Error): UseCaseError()
class BusinessLogic2(val businessLogic2Error: BusinessLogic2Error): UseCaseError()
// any other error that can be generated by a function used by this use case
}
fun useCase(): Either<UseCaseError, String> = TODO()
// Pros:
// Explicit and doesn't lose type information
// Cons:
// Doing this across multiple use cases gets unwieldy
// approach 2
fun useCase(): Either<Throwable, String> = TODO()
// Loses all type info and its only serving as a placeholder to say that the function can fail
Am I missing something? Is there a better approach?pakoito
04/30/2020, 2:22 AMBob Glamm
04/30/2020, 3:06 AMany
in their code nowThomas
04/30/2020, 3:55 AMOption
class I get this (see image), but https://arrow-kt.io/docs/0.10/apidocs/arrow-core-data/arrow.core/-option/ has a truckload of functions available for Option (and IntelliJ agrees).
Obviously I'm missing something... umm... obvious. But I cannot find the API documentation. Help a newbie out?ivanmorgillo
04/30/2020, 4:39 PMIO
is the hardest sell and I need to do the heavy lifting learning it to be able to sell it 😂ivanmorgillo
04/30/2020, 6:20 PMfun areRemindersEnabled(): IO<Unit, Boolean> =
storage.load<Boolean>(key)
.handleError { false }
.mapError { Unit }
Venkat
04/30/2020, 6:23 PMivanmorgillo
04/30/2020, 6:38 PMIO<Boolean>
anymore 🤔Slackbot
05/03/2020, 1:02 PMpakoito
05/04/2020, 9:47 AMpakoito
05/04/2020, 10:50 AMvalidatorAE.validateEmailWithRules(user.email).bind()
cityShouldBeValid(user).bind()
loginShouldNotExit(user).bind()
kobby
05/04/2020, 6:14 PMsuspend fun one(): Either<Error, Int>
suspend fun two(i: Int): Either<Error, Value>
launch{
one().fold(::Left, { right ->
two(right) /// <- Kotlin is complaining that this needs to be in a coroutine scope
}
}
Can you do this?dnowak
05/05/2020, 10:27 AMList<IO<Either<E,A>>>
and I want to stop on first success. How to do this with Arrow?simon.vergauwen
05/05/2020, 12:21 PMfx
completely from that using compiler plugins. I’m looking for other solutions as well in the meanwhile which play nicer with suspend
. All suggestions very welcome.ivanmorgillo
05/07/2020, 2:40 PMsuspend fun loadInt(key: String): Int?
The null
is representing the absence of the value and that's why I was thinking about Either
or Option
, but then there is that problem.
How would you imagine a migration to IO
?
Something like this would work?
fun loadInt(key: String): IO<Int>
CLOVIS
05/07/2020, 3:01 PMBob Glamm
05/07/2020, 3:02 PMivanmorgillo
05/07/2020, 4:36 PMivanmorgillo
05/07/2020, 4:37 PMivanmorgillo
05/07/2020, 5:25 PMBob Glamm
05/07/2020, 5:35 PMjulian
05/07/2020, 7:38 PMfix()
in certain contexts? Sorry folks.pakoito
05/07/2020, 8:44 PMIO.unit.continueOn(Dispatchers.Main)
.followedBy(IO.effect { render(ViewState.Error(it.message ?: "Ooops!")) })
can be
IO(Dispatchers.Main) { render(ViewState.Error(it.message ?: "Ooops!") }
Nico
05/08/2020, 12:28 PMVenkat
05/08/2020, 4:29 PMVenkat
05/08/2020, 4:29 PMBob Glamm
05/08/2020, 4:49 PM.flatten
to make it Option<List<Pair<String, Option<String>>>
, and then maybe describe more about the use case?.traverse
or .sequence
to get to Option<List<Pair<String, String>>> or even Option<Map<String, String>>Venkat
05/08/2020, 4:51 PMBob Glamm
05/08/2020, 4:55 PM.flatMap { it }
== .flatten
Venkat
05/08/2020, 4:57 PMBob Glamm
05/08/2020, 4:59 PM.flatMap { it }.getOrElse(emptyList()).map { it.right() }.sequence().getOrElse(emptyList()) == listOf(/* expected */)
should at least be in the ballparkVenkat
05/08/2020, 5:01 PMBob Glamm
05/08/2020, 5:02 PMVenkat
05/08/2020, 5:02 PMraulraja
05/08/2020, 5:03 PMBob Glamm
05/08/2020, 5:05 PMraulraja
05/08/2020, 5:05 PMval fa: A? = TODO()
val a: A by fa
Venkat
05/08/2020, 5:07 PMraulraja
05/08/2020, 5:08 PMBob Glamm
05/08/2020, 5:08 PMraulraja
05/08/2020, 5:08 PMVenkat
05/08/2020, 5:10 PMraulraja
05/08/2020, 5:10 PMval fa: Option<A> = TODO()
Option.fx {
val a = !fa
... continue unfolding your nested list here
}
!
every Option!
will change to by