Mickey Donaghy
10/01/2020, 1:39 AMOption
is deprecated in 0.11. What's the migration path for functions that I was calling on Option
(specifically traverse
and foldMapM
) - is there an import that will make them available on nullable types or anything like that?Vera van Mondfrans
10/01/2020, 1:19 PMEither
with Flow
when the flow can emit values before coming across something that should cause failure. For example:
fun getNumbersThatAreNotEleven(n: Int): Either<ThatsElevenException, Flow<Int>> =
flow {
for(i in 1..n) {
if (i == 11) {
// sacrilege, what do I do here?
} else {
emit(i)
}
}
}
Satyam Agarwal
10/01/2020, 3:07 PMparTupledN
, it works if i use runBlocking
to run the the test but not with runBlockingTest
. Would be nice if its made possible.Pueffl
10/01/2020, 5:27 PMfun delete(account: EmailAccount): IO<Either<DatasourceFailure, Int>> {
// Implemented
}
fun delete(accounts: List<EmailAccount>): IO<Either<DatasourceFailure, Int>> {
???
}
I'm quite new to FP and the given documentation it is almost impossible to get
the hang of it without having already done FP in another language.thanerian
10/01/2020, 7:22 PMeither<Error, List<String>> {
remote.findByTerm(term)
}.mapLeft { NetworkError }
does not catch the exception, mock is configured in this way using mockito-kotlin
given { runBlocking { remote.findByTerm(any()) } } willThrow { RuntimeException("BOOM!") }
if I use Either.catch{}
the exception is captured correctly and not propagated, is that the intended behavior?Daniel
10/02/2020, 10:54 AMsealed class Error<T> {
data class Network(val throwable: Throwable): ApiError()
data class Server(val throwable: HttpException): ApiError()
data class Api(val response: T)
}
fun register(email: String, password: String): Either<Error<RegisterError>, AuthTokens>
fun login(email: String, password: String): Either<Error<LoginError>, AuthTokens>
I thought that would let me keep Error.Network and Error.Server the same everywhere, and substitute in different Error.Api's for different responses.
The problem is that apparently Kotlin generics don't work like that. I would need to do
sealed class Error {
data class Network(val throwable: Throwable): ApiError()
data class Server(val throwable: HttpException): ApiError()
data class Api<T>(val response: T)
}
fun register(email: String, password: String): Either<Error, AuthTokens>
fun login(email: String, password: String): Either<Error, AuthTokens>
So I lose the ability to specify what kind of Error.Api I return.
Is there a way to avoid this?rcd27
10/03/2020, 7:01 AMNothing
in this: fun <A> absurd(): (Nothing) -> A
, but not Unit
?
https://github.com/arrow-kt/Category-Theory-for-Programmers.kt/blob/master/src/main/ank/1.5-products-and-coproducts.md
Like it is written in CTfP book: "In the category of sets and functions, the initial object is the empty
set. Remember, an empty set corresponds to the Haskell type Void (there
is no corresponding type in C++) and the unique polymorphic function
from Void to any other type is called absurd"
So Nothing
in Kotlin is the initial type for everything else?Ch8n
10/03/2020, 4:34 PMDaniel
10/04/2020, 4:57 PMEither<SomeError, SomeSuccess>
to a SomeError?
, discarding the SomeSuccess. Does a function like that exist in arrow?
Right now I'm just doing the below, but I wanted to know if there is a more idiomatic way
return when (result) {
is Either.Left -> result.a
is Either.Right -> null
}
Jens Suhr
10/05/2020, 7:38 AMevalOn
(with any pool) seems to cause a deadlock in the IntelliJ debugger. This happens with both the whole application in debug mode and a single function in a test. Is there a wrapper or entry point I missed in the docs?Jörg Winter
10/05/2020, 1:43 PMimplementation("io.arrow-kt:arrow-optics:0.11.0")
but my project doesn't seem to find the generated (where?) companion object functions.
I am using a gradle project with IntelliJ and an "@optics" annotated data class ... do I have to include arrow-meta too ?Marius Kotsbak
10/06/2020, 10:07 AMradekm
10/06/2020, 11:18 AMIO
code
val func = IO {
println("some effect")
}
func.retry(arrow.fx.Schedule.recurs(IO.monad(), 3))
into coroutines but I can't find retry
function which works on suspend () -> Unit
. Does it exist or what's the alternative? ThanksSatyam Agarwal
10/06/2020, 4:15 PM0.11.0
, it says Either.fx
is deprecated, and use either { ... }
but !
or .bind()
gives compilation error with either { .. }
with arrow-fx-coroutines
pakoito
10/06/2020, 4:47 PMeither { }
is already a monad transformer because it allows suspend functions inside 😱vio
10/07/2020, 2:53 PMsahil Lone
10/08/2020, 6:20 AMradekm
10/08/2020, 8:47 AMsuspend fun <A, B, C> retryOrElseEither(
schedule: Schedule<A, B>,
fa: suspend () -> A,
orElse: suspend (Throwable, B) -> C
): Either<C, A>
Why is input of schedule
type A
instead of Throwable
? I'm trying to use it but I can't figure howthan_
10/08/2020, 12:23 PMJorge Castillo
10/10/2020, 9:08 AMpakoito
10/10/2020, 1:00 PMMickey Donaghy
10/12/2020, 7:48 AMEither#merge
in Scala - an extension on Either<A, A>
that returns A
? Shall I PR one?Pueffl
10/12/2020, 2:27 PMval parallelValidate = Validated.applicativeNel<ConfigError>()
.tupledN(v1.toValidatedNel(), v2.toValidatedNel()).fix()
.map { (a, b) -> /* combine the result */}
This example works, but it works only for values that are not optional?, so the current implementation is rather useless as you will not have Forms with every field mandatory (or Object with only mandatory fields when you create an instance in map {...} after validating each field.
Should I consider this as a bug and report it or how would I validate a bunch of fields where some of them can be null?stojan
10/12/2020, 4:51 PMkioba
10/12/2020, 6:14 PMoption { }
continuation for nullable types similar to either {}
?genovich
10/13/2020, 2:00 PMAlex Johnson
10/15/2020, 4:17 PMsuspend fun load(): Either<DomainError, DomainResult> = effectCatch(::errorHandler) {
loadDomain()
}
I had used IO and used handleErrorWith to translate errors at my applications boundaries, but perhaps this is cleaner to mostly remove exceptions from my domain?Satyam Agarwal
10/15/2020, 6:30 PMreturn either {
MyDomainObject.left().bind()
}
IDE shows me this : Returning type parameter has been inferred to Nothing implicitly. Please, specify type arguments explicitly to hide this warning. Nothing can produce an exception at runtime.
on v0.11.0 with arrow-fx-coroutines.dephinera
10/15/2020, 8:51 PMcarbaj0
10/16/2020, 3:50 AMoption.fx {}
?
this cannot be achieved with nullable, right?
should I replace it with either.fx { }
?carbaj0
10/16/2020, 3:50 AMoption.fx {}
?
this cannot be achieved with nullable, right?
should I replace it with either.fx { }
?class DebitCardNumber private constructor(
val number: String
) {
companion object {
private const val Mastercard = "^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}\$"
suspend operator fun invoke(number: String): Either<Unit, DebitCardNumber> =
if (number.matches(Mastercard.toRegex())) DebitCardNumber(number).right() else Unit.left()
}
}
IO.fx {
val validCardNumber = !effect { DebitCardNumber(cardNumber) }
Either.fx<Unit, DebitCard> {
VirtualDebitCard(
cardNumber = !validCardNumber,
accountNumber = accountNumber ?: "",
contractNumber = contractNumber ?: "",
cardStatus = cardStatus ?: "",
cancelIndicator = cancelReason ?: "",
cancelReason = cancelIndicator ?: "",
cardAlias = cardAlias ?: ""
)
}
}.suspended()
simon.vergauwen
10/16/2020, 4:50 AMnullable
, and someone is contributing it 🙂 https://github.com/arrow-kt/arrow-core/pull/251carbaj0
10/16/2020, 6:44 AMsealed class Shift<out T>
object Empty : Shift<Nothing>()
data class Result<T>(val result: T) : Shift<T>()
kioba
10/16/2020, 7:19 AMcarbaj0
10/16/2020, 10:48 AM