Questions tagged [arrow-kt]
Λrrow is a library for Typed Functional Programming in Kotlin
130
questions
1
vote
1
answer
42
views
Modify property of sealed interface
I'm trying to modify a property on a sealed interface.
Are optics for properties of a interface not generated? Can I use some kind of Lens/Prism/Iso to access the property?
@Test
fun `Modify field on ...
1
vote
1
answer
38
views
How to build a Lens to "filter and modify" elements of list element? Using Arrow Optics
Using kotlin lib Arrow/optics
Is there a way to build a lens to filter and set/modify a element of list property?
like this code -
@optics
data class Order(val code: String, val lines: List<Line>...
1
vote
1
answer
216
views
How to call Arrow.kt function returning basically Either but using multiple context receivers
Arrow.kt docs point out that instead of:
fun get(): Either<Err, Res>
we can use
context(Raise<Err>)
fun get(): Res
And we can even have multiple context receivers.
Imagine we have two ...
0
votes
0
answers
41
views
Why doesn't Ior have a specific type for "warning" in Arrow-kt?
Why does Ior have only two generic types as parameters?
Isn't this inconsistent with the benefits of typed errors, since a "warning" can be different from an "error"?
Doesn't this ...
0
votes
1
answer
104
views
Mocking a service that uses a context receiver Raise<BusinessError> using Mockito
Source code available on Github: https://github.com/codependent/context-receiver-sample
Suppose you're testing a service ServiceOne that has a dependency on ServiceTwo.
ServiceTwo has a method call() ...
0
votes
1
answer
311
views
How can we use context receivers and Arrow 1.2.0 parZipOrAccumulate? No required context receiver found: Cxt
Given the following functions:
context(Raise<ApplicationError>)
suspend fun getUser(legalId: UserLegalId): User
context(Raise<ApplicationError>)
suspend fun getDepartment(departmentCode: ...
0
votes
1
answer
92
views
Can't bind when accumulating errors into a Nel<ApplicationError> using Arrow 1.2.0 parZipOrAccumulate
I'm using the new parZipOrAccumulate function from Arrow 1.2.0-RC to parallelize two calls and accumulate their errors if any:
private suspend fun getUser(legalId: UserLegalId): Either<...
0
votes
0
answers
88
views
LiveData not captured when unit testing Either.fold()
I'm trying to add unit tests to a project that we've inherited from another company, but I can't manage to make them work since I'm not very experienced with testing and I never used the Arrow-kt ...
0
votes
1
answer
177
views
How to flatten Arrow-KT's either and Kotlin Coroutines' Flow
I've been using Arrow-KT for a long time now. I'm much newer to coroutines and the programming model around them, this is my first project using them. I've got the following scenario:
Either.catch { ...
0
votes
1
answer
121
views
How to create a member variable of Arrow Atomic in kotlin
Arrow-fx has a type Atomic which is similar to java AtomicRef but with an initial value, which means I don't need to check every time while accessing the atomic value whether it's null.
Here is a ...
0
votes
1
answer
159
views
How to create an alias to bind method in Arrow-kt?
In Arrow-kt I'd like to create an alias to the bind() - for a kind of custom lib to use Arrow.
I'd expect the following to work but it doesn't:
suspend fun <F, S> Either<F, S>.bindMy(): S =...
1
vote
1
answer
162
views
Kotlin Arrow EffectScope.shift() implementation throws exception?
When looking at arrows documentation about functional error handling one of the reason listed to avoid throwing exceptions is performance cost (referencing The hidden performance costs of ...
3
votes
1
answer
302
views
Convert java Optional to Kotlin Arrow Option
What would be the best way to convert Java Optional to Arrows Option? I was expected to have something out-of-box, but it's not there. Something like:
fun <T> Optional<T>.toOption(): ...
1
vote
1
answer
184
views
How do you add/remove an element of immutable list using Arrow Optics?
I have a complicated, immutable data structure that includes simple fields, but also maps and lists in the hierarchy. Maybe I'm just not reading the documentation closely enough, but there doesn't ...
2
votes
1
answer
360
views
kotlin.NoWhenBranchMatchedException under unit testing a tailrec function with arrow-kt in the mix
I'm testing a function with an external dependency inside of a tailrec function. The function returns an Either.
When mocking this dependency, I'm providing a single mock invocation. I get the ...
-1
votes
1
answer
100
views
Best approach with arrowKt and repositories [closed]
I have an usecase on my work and I want to discuss with you what should be the best approach to do it.
In repository functions that should finds only one line what should be the best approach, return ...
3
votes
1
answer
539
views
The Reader Monad in Kotlin with arrow-kt
I working on a medium-sized Kotlin project where I need to thread configuration information read from file through many nested calls of pure functions. This seems to be an obvious case for the Reader ...
1
vote
1
answer
238
views
How can you paralellize the processing of File InputStreams in Kotlin / Arrow?
I am processing large Files, having a list of them:
val originalFiles: List<File>
I need to read the InputStream of each file, process it, and write it to another processedFile. For the sake of ...
0
votes
2
answers
60
views
Kotlin + Arrow-kt - why are my coroutines not cancelling properly?
I am using Kotlin together with Arrow-Kt libraries.
I am launching on a specific scope some coroutines that make use of Arrow-kt's Schedule.
At a certain time, I want to be able to cancel all those ...
0
votes
1
answer
69
views
Arrow Analysis throws "NosuchMethod" exception
I'm trying to use arrow analysis in my project to catch exceptions at compile time. I follow this page but when I do Gradle build I get a bunch of runtime exceptions
It's my test code
fun main() {
...
2
votes
1
answer
186
views
How use arrow-kt to convert a function taking two parameters into a function taking a pair?
I wrote this goofy tuplize function:
fun foo(x: Int, y: Int) = 3 * x + 2 * y + 1
fun <T, U, R> tuplize(f: (T, U) -> R): ((Pair<T, U>) -> R) = { (a, b): Pair<T, U> -> f(a, b)...
1
vote
1
answer
564
views
Kotlin Arrow - 'option' is deprecated. Deprecated in favor of the Effect or EagerEffect Runtime
I'm getting below depreciation warning in arrow 1.1.2, could anyone please tell me what's the correct replacement for this?
[DEPRECATION] 'invoke(crossinline suspend OptionEffect<*>.() -> A?)...
6
votes
1
answer
432
views
Why does ArrowKt reccomend I implement my effect interface with an object instead of a function?
According to the docs I should implement an effect with an object.
fun interface JustEffect<A> : Effect<Just<A>> {
suspend fun <B> Just<B>.bind(): B = value
}
object ...
0
votes
1
answer
137
views
Arrow.kt loading state
I used arrow.kt library so many times, I really enjoyed the features they gave to extend kotlin. I like how Either<E,T> can represent the success/failed states seamlessly. I am just wondering if ...
2
votes
2
answers
245
views
arrow ensure doesn't make value non nullable after check
have a question about ensure function, somehow it doesn't make null safe after check in either block.
What I am doing wrong, or is there a better way to ensure that value is not null except of using !!...
1
vote
1
answer
41
views
Why does `EffectScope.shift` need the type parameter `B`?
The move to the new continuations API in Arrow brought with it a handy new function: shift, in theory letting me get rid of ensure(false) { NewError() } or NewError().left().bind() constructs.
But I'm ...
1
vote
1
answer
325
views
arrow validation more then 10 fields
all I have a question how can I validate more then 10 values with arrow in kotlin.
fun CreateEventDTO.validate(): Validated<IncorrectInput, CreateEventDTO> =
name.isEventNameValid()
.zip(
...
2
votes
2
answers
1k
views
Unresolved reference in Kotlin optic data class reference
Was playing a bit with arrow library for Kotlin and found this error right out of the documentation https://arrow-kt.io/docs/optics/ . What am I doing wrong?
Unresolved reference: company
the code ...
1
vote
1
answer
1k
views
Mixing Eithers and other exceptions inside an either.eager
I have code I've written inside an either.eager
return either.eager<MyException, MyResponse> {
val objList = service.getObjs().bind()
val obj = objList.find{...} ?: throw MyException....
2
votes
1
answer
330
views
Is there any reason to use suspend fun fn(...): Either<Throwable, A> instead of suspend fun fn(...): A?
I'm mulling over something regarding suspend that Arrow's documentation explains in detail: suspend () -> A offers the same guaranties as IO<A>.
So, according to the documentation, just using ...
8
votes
1
answer
685
views
Which should we choose between Effect and Either as a return type of our business services?
With the arrival of Arrow 1.1.x we got the new Effect class.
Up to now, my business classes returned Either to model the effect of returning an error or a value, e.g.:
@Service
class ...
0
votes
2
answers
139
views
Closing (Auto)Closeables that exist only in `Either`
I currently face the problem of correctly closing resources that never leave their containing Either.
The relevant code looks something like this:
object SomeError
class MyRes : AutoCloseable { [...] }...
4
votes
1
answer
924
views
How to use Either monad and avoid nested flatMap
I'm in a situation where I'm trying to setup some data and then call a service. Each step can fail, so I'm trying to use Arrow's Either to manage this.
But I'm ending up with a lot of nested flatMaps.
...
2
votes
1
answer
117
views
Iso generation is supported for data classes with up to 22 constructor parameters
@optics data class test( 1,2,...23) {
companion object
}
[ERROR] Iso generation is supported for data classes with up to 22 constructor parameters.
1
vote
1
answer
292
views
is ValidatedNel arrow-kt in v1.0 still an Applicative (Functor)?
I understand that in previous versions of Arrow-Kt was an instance of the Applicative typeclass. In the current version 1.0.x, most typeclasses are no longer present/visible (to make the library more ...
0
votes
1
answer
121
views
Access a shadowed receiver
I would like to combine a Kotlin extension function on some receiver class Receiver with arrow-kt's either comprehension. In a regular Kotlin extension function, this binds to the receiver object; ...
2
votes
1
answer
872
views
How to propage errors from nested Eithers in Arrow-kt?
I have some code that looks like this:
data class MyStrings(val a: String, val b: String)
sealed class Error {
object SpecificError0 : Error()
object SpecificError1 : Error()
object ...
3
votes
1
answer
332
views
Is there a way to use monad comprehensions with Kotlin Flow
Kotlin coroutines and Arrow are a nice way to avoid nesting flatmaps, introducing monadic comprehensions in Kotlin. However Kotlin's Flow type still relies on declarative flatmapping, so we get into a ...
5
votes
2
answers
916
views
Relation between Arrow suspend functions and monad comprehension
I am new to Arrow and try to establish my mental model of how its effects system works; in particular, how it leverages Kotlin's suspend system. My very vague understanding is as follows; if would be ...
0
votes
2
answers
2k
views
how to configure ksp in my android gradle groovy dsl build files
im investigating the io.arrow.kt functional programming library in my current android project.
im having difficulty in configuring the optics module that employs ksp for source code generation
my ...
1
vote
1
answer
953
views
Handling an Arrow-kt Either inside a map
My question is somewhat related to Kotlin arrow-kt Flatten nested Either, but also not exactly.
I have a list that I map through, and within this map I call a function that returns an Either. If the ...
10
votes
2
answers
1k
views
Kotlin - Infer type for one of two generic parameters
I am trying to create a function that has two generic types: one reified, and another derived from the context of its usage (since it is an extension function):
inline fun <reified E, A> Either&...
0
votes
1
answer
477
views
Creating an object builder with error handling using Arrow - Pattern match multiple Eithers
I have class A:
class A (private var z: String, private var y: String, private var x: Int)
I want to create a failsafe builder for it. The builder should return Either the list of Exceptions (e.g. ...
0
votes
1
answer
333
views
How to map 2 Either values without tupled
I need to take 2 values, each of them is Either<Throwable, Any> and combine them together (or to do anything else) if each of the values is Right.
For arrow-kt 0.11.0 it was possible with tupled
...
0
votes
1
answer
664
views
Arrow-kt: how to turn an Either<E, List<Either<E,A>>> into Either<E, List<B>>
I receive an Either<E, List<A>> from a function call and need to transform the List<A> into a List<B>. The transformation of each A returns an Either<E,B>, so that my ...
4
votes
1
answer
700
views
How to keep use cases and entity layer in Functional Clean Architecture pure when having database read/write interactions?
Intro
I've been diving into functional programming in the last few months, and since I'm really intrigued by the Kotlin language, I've been using the Arrow library to toy around with a few things.
A ...
1
vote
2
answers
974
views
Processing async results with Arrow-kt and Kotlin
I have two async function calls to external systems returning Either<Exception, Something> and need to combine their results. Being a beginner in functional programming in Arrow-Kt, I am ...
7
votes
2
answers
2k
views
Kotlin's Arrow Either<Exception, X> and transactions
I am trialing the use of Kotlin's Arrow library Either object to handle exceptions within a project.
My experience with it thus far has been OK, but I'm struggling to find a way to handle transactions ...
7
votes
1
answer
602
views
implement a monad comprehension on a list in kotlin using a coroutine
I wonder if it is possible to implement something similar to the do-notation of Haskell in Kotlin on Lists or List-Like structures with monadic properties.
Take following example:
fun <A, B> ...
2
votes
2
answers
414
views
Cut pairs with empty values from map
I'd like to filter out all the pairs with empty values
val mapOfNotEmptyPairs: Map<String, String> = mapOf("key" to Some("value"), "secondKey" to None)
expected:
...