Quantum64
04/30/2022, 5:39 PMSatyam Agarwal
05/01/2022, 11:44 AMIor.fromNullables(Nel.fromList(list1).getOrElse { null }, Nel.fromList(list2),getOrElse { null})
This is obviously not good, as Nel<A>?
effectively means List<A>
, so i can just list1.isEmpty() && list2.isEmpty
to cover Ior
cases.
However, what I want is Nel
after checking the states.
Is there something better that can be done here ?
Pattern matching on Option<Nel<A>> to Option<Nel<B>>
also doesn’t work. I can’t say for example when exp is Pair<Some, None>
Robert Kittilsen
05/03/2022, 12:29 AMfun getSignedUrl(fileName: String): Either<FileError, URL>
in which I Either.catch
a generation of a signed URL and mapLeft
for a potential FileError.SignedUrlError
.
In another service I have a function that looks like this: fun getReports(): Either<GeneralError, List<Report>>
. In this I’m mapping through each report and replacing filenames with a call to getSignedUrl
. I want to do it eagerly and go left on first fail.
In the end I’m folding into a HttpResponse like this: fun <BODY> Either<GeneralError, BODY>.toResponse(): HttpResponse<BODY>
As you can see I have two different Error objects and nested Either’s.
The only solution I’ve found without changing FileError.SignedUrlError
into GeneralError
is something like this:
fun <OUTER_TYPE, INNER_TYPE, ERROR_TYPE> Collection<OUTER_TYPE>.mapEitherReturningFirstLeft(block: (item: OUTER_TYPE) -> Either<ERROR_TYPE, INNER_TYPE>): Either<ERROR_TYPE, List<INNER_TYPE>> =
this.map { item ->
block(item).fold(
ifRight = { it },
ifLeft = { return it.left() }
)
}.right()
This doesn’t seem optimal. Any suggestions or thoughts will be much appreciated! 🤩julian
05/03/2022, 1:40 AMEffect
. It all made sense to me, except for this:
Only whenWhat does pure values mean? I know what a pure function is, but I don't think I've ever come across pure values.is called it will create afold
and run the computation, this meansContinuation
can encodeEffect
asside-effects
.pure values
genovich
05/04/2022, 4:34 PMraceN()
probably not handling exceptions in a right way.
According to the conversation I had a year ago, it seems to me that if one of functions will throw an exception, then another will not be cancelled.
Do you have an idea how to check such behaviour?Jose Antonio Jimenez
05/06/2022, 10:41 AM> Failed to query the value of task ':kspKotlin' property 'options'.
> Could not resolve all files for configuration ':kspKotlinProcessorClasspath'.
> Could not find io.arrow-kt:arrow-optics-ksp-plugin:1.0.1.
Required by:
project :
Stylianos Gakis
05/09/2022, 12:27 PMfun getLoginResult(): Success|WrongPassword|NetworkError
Would you map this to Either<NetworkError,Success|WrongPassword>
or Either<NetworkError|WrongPassword,Success>
?
I also understand that both can work, technically one could flip Right and Left too, but we’re trying to see what the “convention” is to try and conform to whatever feels more standard.
Feel free to respond here or there, either works for us, but probably here so that other people can benefit in the future.Marko Novakovic
05/09/2022, 12:33 PMFlow
and Either
? is having Flow<Either<A, B>>
a good option?
also, are there any plans for some monadic streaming Flow-like API?bloder
05/10/2022, 11:15 PMEffect
feature, really cool how I can type all my effects and play with them purely, one doubt about it: Are we thinking in explore more about Algebraic Effects and bring its concept to this implementation?Oliver Eisenbarth
05/14/2022, 4:36 PMeffect
? Please explain it to me like I'm five. 🙂alightgoesout
05/15/2022, 5:07 PMEffect
like leftIfNull
for Either
?
Right now I do:
effect {
ensureNotNull(someEffect.bind()) { SomeError("…") }
}
which seems verbosePavel
05/16/2022, 7:26 AMEffect
I would have one question too. Is it possible to compose multiple `Effect`s? For example:
fun test(): Effect<X, Int> = effect {
1
}
fun test2(num: Int): Effect<X, Int> = effect {
num + 1
}
(test().flatMap { num -> test2(num) }): Effect<X, Int>
than_
05/16/2022, 9:14 AMsealed interface DomainError
object SomeDomainError: DomainError
fun foo(): Effect<DomainError, Unit> = TODO()
fun bar(): Effect<SomeDomainError, Unit> = TODO()
fun baz() = effect<DomainError, Unit> {
foo().bind()
bar().bind()
}
the problem is I cannot bind result of bar
even though SomeDomainError
is a DomainError
. Is this known limitation, oversight, or weirdness on my side 🙂 ?jianbing
05/19/2022, 7:45 AMKatarzyna
05/19/2022, 1:08 PMMarko Novakovic
05/20/2022, 3:01 PMEffect
. can somebody give me concrete example where difference between Effect
and Either
is clear?Łukasz Gendek
05/23/2022, 7:33 AMSatyam Agarwal
05/24/2022, 5:02 AMjean
05/25/2022, 8:25 AMfun interface PatchDevice<T> {
suspend operator fun invoke(
deviceId: String,
payload: T
): Either<Error, Action>
}
fun interface PatchDeviceAttribute<T> {
suspend operator fun invoke(
deviceId: String,
payload: T
): Either<Error, Action>
}
suspend fun <T> save(
patchDevice: PatchDevice<T>,
patchDeviceAttribute: PatchDeviceAttribute<T>
) {
either.eager<> {
val patchDeviceResult = patchDevice("")
}
}
The IDE complains that Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope
when I call patchDevice()
What should I change to make it work?kyleg
05/25/2022, 2:59 PMIO<A>
hadn't been deprecated for suspend yet!).
Quick question: didn't Arrow used to have a Free/FreeMonad implementation? I can't seem to find it in the codebase or the docs now. I found a gist for creating a DSL using Arrow (written three years ago) but I can't even find annotations like @higherkind
to import them. It looks like there used to be a module arrow-free or something based on links in the gist, but I can't find that now.Satyam Agarwal
05/27/2022, 9:05 AMimport arrow.core.computations.ResultEffect.bind
@Test
fun `encrypt produces new encryption for given text and should be decrypted back `() {
val text = "Some sensitive data :partying_face: 2020-06-27T19:11:44.095Z @#$%^&*(&^%$#@! åååå πø˜˜¶∞¢"
val textByteArray: ByteArray = text.toByteArray()
val firstEncryption: ByteArray = Crypto.encrypt(securityKey, textByteArray).bind()
val secondEncryption: ByteArray = Crypto.encrypt(securityKey, textByteArray).bind()
firstEncryption shouldNotBe secondEncryption
val firstDecryption: ByteArray = Crypto.decrypt(securityKey, firstEncryption).bind()
val secondDecryption: ByteArray = Crypto.decrypt(securityKey, secondEncryption).bind()
firstDecryption shouldBe textByteArray
secondDecryption shouldBe textByteArray
String(firstDecryption) shouldBe text
String(secondDecryption) shouldBe text
}
Is there some alternative, or am I forced to migrate my hundreds of tests 😅Marko Novakovic
05/30/2022, 11:47 AMsuspend fun createTask(
tasksDao: TasksDao,
localDate: LocalDate,
label: String,
): Either<TaskError, Unit> = either {
ensure(label.isNotBlank()) { TaskError.EmptyLabel }
try {
tasksDao.createTask(localDate.year, localDate.monthNumber, localDate.dayOfMonth, label)
} catch (e: Throwable) {
shift(TaskError.CreationError)
}
}
but it fails to compile for iOS target, Task :shared:linkDebugTestIosSimulatorArm64 FAILED
happens on 1.1.2 and 1.1.3-alpha.14
works for Android
error in threadstojan
05/31/2022, 1:26 PMsimon.vergauwen
05/31/2022, 2:32 PMMoritz Lindner
06/01/2022, 8:29 PMEither<A, Option<B>
and want to create a Either<A, B>
. If the Option is None
the Either should be Left<A>
and if it is Some
I want the Either to be Right<B>
.
I did not find a function in the library and since MonadeTransformers are not an option I came up with the following solution:
fun <A, B> Either<A, Option<B>>.unwrapOptionOrElse(other: () -> A): Either<A, B> {
return flatMap { option -> option.fold({ other().left() }, { it.right() }) }
}
Is this a reasonable way of handling this case or should I change something?
Regards Moritz 🙂jean
06/02/2022, 7:34 PMError while evaluating property 'filteredArgumentsMap' of task ':compileKotlinMetadata'
> Could not resolve all files for configuration ':metadataCompileClasspath'.
> Could not resolve io.arrow-kt:arrow-core:1.1.2.
Required by:
project :
> The consumer was configured to find a usage of 'kotlin-api' of a library, preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common'. However we cannot choose between the following variants of io.arrow-kt:arrow-core:1.1.2:
- iosArm32ApiElements-published
- iosArm64ApiElements-published
- iosSimulatorArm64ApiElements-published
- iosX64ApiElements-published
- jsApiElements-published
- jvmApiElements-published
- jvmRuntimeElements-published
- linuxX64ApiElements-published
- macosArm64ApiElements-published
- macosX64ApiElements-published
- mingwX64ApiElements-published
- tvosArm64ApiElements-published
- tvosSimulatorArm64ApiElements-published
- tvosX64ApiElements-published
- watchosArm32ApiElements-published
- watchosArm64ApiElements-published
- watchosSimulatorArm64ApiElements-published
- watchosX64ApiElements-published
- watchosX86ApiElements-published
this is my commonMain
val commonMain by getting {
dependencies {
implementation("io.arrow-kt:arrow-core:1.1.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1-native-mt")
}
}
Am I missing something here? I tried to add other multiplatform dependencies like ktor, and it did not have the same issue, it compiled just fineDaniel Wojda
06/06/2022, 9:35 AM./gradlew spotlessApply
Unfortunately, the task fails with following error:
FAILURE: Build failed with an exception.
* What went wrong:
Task 'spotlessApply' not found in root project 'arrow'.
Did I miss some configuration step?Luke
06/14/2022, 9:11 PM(T) -> R
) and another parameter of type T
and returns a lambda with no parameter (() -> R
) which when called runs the parameter lambda ((T) -> R
) with the instance of T
?tavish pegram
06/17/2022, 5:37 PMPartho Paul
06/22/2022, 11:16 AMfun f1(): Either<Throwable, String> {
either {
doSomething() //throws exception
}
}
fun f2() {
f1().fold(
{
print("you messed up")
doErrorHandling()
},
{
print("everything's fine")
}
)
}
fun main() {
runCatching{
f2()
}
.onSuccess {
print("it worked")
}
.onFailure {
print("Either didn't catch exception")
}
}
When function f1() throws exception here, the code should print “you messed up” but instead it’s printing “Either didn’t catch exception”. Am I doing anything wrong here? I’m using kotlin 1.7.0 and arrow version 1.1.2
TIAPartho Paul
06/22/2022, 11:16 AMfun f1(): Either<Throwable, String> {
either {
doSomething() //throws exception
}
}
fun f2() {
f1().fold(
{
print("you messed up")
doErrorHandling()
},
{
print("everything's fine")
}
)
}
fun main() {
runCatching{
f2()
}
.onSuccess {
print("it worked")
}
.onFailure {
print("Either didn't catch exception")
}
}
When function f1() throws exception here, the code should print “you messed up” but instead it’s printing “Either didn’t catch exception”. Am I doing anything wrong here? I’m using kotlin 1.7.0 and arrow version 1.1.2
TIAstojan
06/22/2022, 11:28 AMEither.catch {}
or similar functions e.g.
Either.catch { doSomething() }
Partho Paul
06/22/2022, 11:29 AMAlejandro Serrano Mena
06/22/2022, 11:41 AMEither.catch
within an either
block a bit confusingfun f1(): Either<Throwable, String> =
Either.catch { doSomething() }
or you need to call bind
to make the block aware of the thing being run
fun f1(): Either<Throwable, String> {
either {
Either.catch { doSomething() }.bind()
}
}
Partho Paul
06/22/2022, 11:43 AMfun f1(): Either<Throwable, String> {
Either.catch {
doSomething() //throws exception
}
}
fun f2() {
f1().fold(
{
print("you messed up")
doErrorHandling()
},
{
print("everything's fine")
}
)
}
fun main() {
runCatching{
f2()
}
.onSuccess {
print("it worked")
}
.onFailure {
print("Either didn't catch exception")
}
}
Alejandro Serrano Mena
06/22/2022, 11:44 AMfun f1(): Either<Throwable, String> =
Either.catch { doSomething() }
(note that I'm using =
and not braces)Partho Paul
06/22/2022, 12:37 PMfun f1(): Either<Throwable, String> =
Either.catch { doSomething() }
but still not able to catch exception in f2stojan
06/22/2022, 12:40 PMEither.catch
is basically a `try/catch`https://github.com/arrow-kt/arrow/blob/051847de3b1d3186fc9843864aaf642a2f4a854f/ar[…]libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt
except if your exception is fatal e.g.: https://github.com/arrow-kt/arrow/blob/0afdd9a7cc5251cf0c50701b21ccbb5693045bde/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/NonFatal.kt#L10Partho Paul
06/22/2022, 12:55 PMraulraja
06/22/2022, 2:51 PMLinkageError
, how did you plan to recover from it? and what leads you to this point where you care about it in user code?Partho Paul
06/22/2022, 3:39 PMLinkageError
. I’m migrating a legacy codebase into a new microservice. I’ll discuss it with my colleagues if we should continue the earlier workflow or short-circuit the process. I’ll be in favour of short-circuiting as continuing the earlier workflow will make the system less reliable.raulraja
06/22/2022, 4:53 PMLinkageError
is fatal and usually means you are missing a native library file in the path and your application should not even be running at that point. Exceptions would be some kind of local application where the user is responsible to provide the linked libraries manually but that is an odd case. Normally you can’t recover from fatal exceptions because at that point for many of them you don’t even have guarantees the VM is in a recoverable state, for example OutOfMemoryError