Questions tagged [arrow-kt]
Λrrow is a library for Typed Functional Programming in Kotlin
101
questions
1
vote
1
answer
32
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 ...
4
votes
1
answer
76
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
34
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 { [...] }...
2
votes
1
answer
49
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.
...
1
vote
1
answer
30
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
45
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
29
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; ...
1
vote
1
answer
107
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 ...
2
votes
1
answer
107
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 ...
3
votes
2
answers
198
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
1
answer
243
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 ...
0
votes
1
answer
196
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 ...
3
votes
1
answer
154
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
106
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
53
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
48
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
389
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
484
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 ...
6
votes
2
answers
1k
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
375
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
92
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:
...
1
vote
2
answers
176
views
Can I use Kotlin Arrow-lib with Quarkus in native builds
I started a new Kotlin project and i want to use the arrow-kt core Lib in combination with Quarkus (1.12.2). I want to use the native compilation feature of Quarkus with the GraalVM. My first thought ...
5
votes
1
answer
533
views
Can anyone motivate why Arrow (Kotlin) choose to deprecate higher-kinded types?
Digging into the codebase of Arrow I found this deprecation warning above higher-kinded types.
Higher Kinded types and their related type classes will no longer be
supported after Arrow 0.13.0. Most ...
0
votes
1
answer
41
views
improving applicativeNel validation when result should have the value or nothing
I am currently learning to use ArrowKT and I have the following code for validating an input. I tried to collect all the errors at once and execute the validations in parallel since most of them are ...
4
votes
3
answers
1k
views
Kotlin arrow-kt, functional way to map a collection of either to an either of a collection
I've been using kotlin arrow quite a bit recently, and I've ran into a specific use case that has me stuck.
Let's say I have a collection of some object that I want to convert to another datatype ...
1
vote
1
answer
209
views
Exceptions thrown while generating a sequence
I want to copy a potentially huge file from one place to another (for example, but not limited to, the local filesystem). In order to decouple the reading from the writing, my copy flow has steps to ...
4
votes
1
answer
166
views
Kotlin equivalent of some F# code matching on union type
I'm learning Kotlin and am wondering if anyone out there could advise on what the following snippet of F# might look like in idiomatic Kotlin.
// a function that has an Option<int> as input
let ...
3
votes
1
answer
748
views
How to efficiently flatten a list of Either in Kotlin
I have a list something like this List<Either<Failure, List<MyResult>>> and would like to flatten it to Either<Failure, List<MyResult>> using Arrow-kt but everything I've ...
0
votes
1
answer
309
views
FP patterns for combining data from different sources (preferrably in Kotlin and Arrow)
Disclaimer upfront: Recently, my interest in functional programming has grown and I've been able to apply the most basic approaches (using pure functions as much as my knowledge and working ...
0
votes
1
answer
168
views
Arrow lens won't let me set a nullable property to null
Given this (extremely simplified) code :
@optics
data class MigrationStatus(val token: String?)
val m = MigrationStatus(null)
I can call
val m1 = MigrationStatus.token.modify(m) { "some token&...
0
votes
1
answer
94
views
Can you convert this code to monad comprehensions using Arrow FX?
Can you convert this reactive method to an Arrow Fx Project Reactor monad comprehension?
class ApplicationServiceImpl(private val applicationRepository: ApplicationRepository,
...
0
votes
1
answer
114
views
How to execute asyncronously inside an Arrow + Reactor Monad comprehension
In he following piece of code, every helloX() method runs asynchronously (it's a deferred Mono that runs in a separate thread), see full code below):
override fun helloEverybody(): Kind<...
0
votes
1
answer
185
views
Why is ! operator the same as .bind() in Arrow Monad comprehension?
One of the ways we can bind() in an Arrow monad comprehesion is "yelling" (third example):
/**
* All possible approaches to running [Kind] in the context of [Fx]
*
* ```
* fx {
* val ...
1
vote
1
answer
133
views
Destructuring instead of .bind() doesn't work in an Arrow Monad comprehension
According to Arrow's Javadoc there are three ways of binding over a monad:
/**
* All possible approaches to running [Kind] in the context of [Fx]
*
* ```
* fx {
* val one = just(1).bind() // ...
1
vote
1
answer
407
views
Difference between Kotlin arrow IO, IO.fx, IO !effect
I am trying to use arrow in kotlin
Arrow has three functions
IO {}
IO.fx {}
IO.fx { !effect}
I want to know the difference between these. I know IO.fx and IO.fx {!effect} help us use side effects but ...
1
vote
1
answer
139
views
Kotlin - Composition of multiples IO
I'm new to Kotlin's Arrow Framework and I have a couple of questions:
Lets suppose
fun getUser(id: Int): IO<Option<User>>
fun getCards(user: User): IO<List<Card>>
fun ...
0
votes
1
answer
145
views
webflux.fn with coroutines: Returning a flow indicates success but has no content in the body; Why is it empty?
I have been tasked with migrating some Reactor based services to webflux.fn + coroutines.
The service generates a png compass image. I see the bytes of the compass before they are returned to Postman ...
1
vote
2
answers
296
views
Is it possible to use Kotlin's by-delegation with an existing class/object (i.e.Arrow's Either)?
I have a few specialized classes that I would like to create using Kotlin and Arrow and they will wrap around an Arrow Either monad. I've created the following code to use Kotlin's delegation, but I ...
0
votes
2
answers
494
views
How to chain functions returning Validated, Option, Either? (Monad Transformer)
I have simple three functions returning arrow-kt data types
fun validate(input): Validated<Error, Input> = ...
fun fetch(input): Option<Error, InputEntity> = ...
fun performAction(...
3
votes
2
answers
893
views
Kotlin elegant way to mutate List<Triple<String, String, String> to Triple<List<String>, List<String>, List<String>>
I'd like, as succinctly (yet clearly) as possible to transform a List<Triple<String, String, String> to a Triple<List<String>, List<String>, List<String>>.
For ...
1
vote
2
answers
137
views
How can I access the context in every function of a call chain with Kleisli?
I have a call chain of some methods, where I pass a context via a Kleisli. Basically I want to pass a context down to the db access layer, but I want to access this context everywhere in between.
The ...
2
votes
1
answer
679
views
How to compose IO functions with other effects in Kotlin Arrow FX
We often need some request validation before handling it. With arrow v 0.8 a typical message handler looked like:
fun addToShoppingCart(request: AddToShoppingCartRequest): IO<Either<...
4
votes
1
answer
4k
views
Extract value out of Kotlin arrow Either type and assign it to const
It would be a basic question, but I couldn't figure out a solution. I need to initialize a constant out of the right-side value of below either type.
val test: Either<String, Int> = 1.right()
...
0
votes
1
answer
83
views
IO dispatchers VS KotlinX dispatchers inside an fx block
when using IO, in an fx block I can use continueOn with dispatchers.io() but also Dispatchers.IO or I can mix. Is there a preferred way? Is there any difference between the two?
Note: I am also ...
1
vote
2
answers
179
views
Cast away nested Option in Kotlin arrow
I have a value with below type in my data class
Option<Option<List<Pair<String, Option<String>>>>>
How would I access the right-most Option<Sring>. I have tried ...
0
votes
1
answer
116
views
How to append data in Functional programming style using kotlin with arrow library
I'm new to functional programming and I'm using Kotlin with arrow functional library. I would like to convert below function to pure. Each func*() call returns a valid string and it's gets appended to ...
1
vote
1
answer
818
views
Understanding Validated.applicative in kotlin arrow library
I come across below generic function which takes two Either type and a function as an argument. If both arguments are Either.Right then apply the function over it and returns the result, if any of the ...
1
vote
1
answer
2k
views
return type of Either.fold() in Kotlin arrow library
I'm learning functional programming in Kotlin using arrow library and I come across below strange behaviour of fold function of Either type (at least for me).
import arrow.core.*
import arrow.syntax....
1
vote
1
answer
224
views
How implement Arrow Kt with Android ViewModel?
In Android network operations are usually done within ViewModel. This ensures that even when the Activity or Fragment is recreate (for example when device is rotated), the network call keeps going and ...
0
votes
1
answer
195
views
Dependency Injection on Arrow KT
In Arrow Kt Documentation on Dependency Injection, the dependency is defined at the "Edge of the World" or in Android could be an Activity or a Fragment. So the given example is as follow:
import Api....