Questions tagged [arrow-kt]
Λrrow is a library for Typed Functional Programming in Kotlin
82
questions
3
votes
1answer
37 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
2answers
52 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:
...
0
votes
2answers
33 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 ...
2
votes
1answer
121 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
1answer
27 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 ...
3
votes
2answers
113 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
1answer
71 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
1answer
106 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 ...
1
vote
1answer
127 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
1answer
65 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
1answer
55 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
1answer
55 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
1answer
53 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
1answer
67 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
1answer
35 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
1answer
258 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
1answer
93 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
1answer
76 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
2answers
102 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
2answers
150 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(...
2
votes
2answers
274 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
2answers
74 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
1answer
443 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<...
1
vote
1answer
1k 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
1answer
64 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
2answers
86 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
1answer
57 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
1answer
306 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
1answer
832 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
1answer
104 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
1answer
112 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....
1
vote
1answer
49 views
How to cancel arrow-kt IO?
Is is possible to cancel an (Arrow-Kt) IO?
In RxJava whenever I do observable.subscribe({ // handle success },{ // some errohandling }), I am given a Disposable which I could call Disposable.dispose(...
0
votes
1answer
154 views
Arrow KT: Reader Monad vs @extension for Dependency Injection
I've read about Reader Monad from this article by Jorge Castillo himself and I've also got this article by Paco. It seems that both tackles the idea of Dependency Injection just in a different way. (...
3
votes
2answers
573 views
Arrow-Kt Fx vs Kotlin Coroutines
I am trying to learn Arrow-Kt since I got curious about Functional Programming in Kotlin.
Can someone explain why there is a need to create another construct that functions almost similarly to Kotlin ...
0
votes
1answer
81 views
How to call a polymorphic function which depends on multiple Typeclasses in Kotlin/Arrow
I've created a function which is polymorphic in the Monad it needs to use, instead it depends on the typeclass instances that exists for this Monad. It looks like this:
fun <M> M.logic(...): ...
1
vote
1answer
239 views
ArrowKt Try alternative for eager execution
ArrowKt has deprecated Try since it promotes eager execution of effects and it recommends to use suspend constructors.
But how should I handle following case where I do want eager execution on ...
1
vote
3answers
321 views
Map list of Options to list of Strings
I've been using Arrow Kotlin quite a lot recently but I'm still confused on how to map a list of options to their values. For example:
val listOfStrings: List<String> = listOf<Option<...
2
votes
0answers
86 views
Why use Kind<F, A> instead of F<A>
Whenever you read Arrow.kt tutorials, as they progress, they start touting as a benefit of FP that you can abstract away your types and write everything as things like fun <F> myFun(): Kind<F,...
0
votes
1answer
73 views
With Arrow: How do I apply a transformation of type (X)->IO<Y> to data of type Sequence<X> to get IO<Sequence<Y>>?
I am learning functional programming using Arrow.kt, intending to walk a path hierarchy and hash every file (and do some other stuff). Forcing myself to use functional concepts as much as possible.
...
0
votes
0answers
56 views
Leaking Android UI with Arrow-kt IO.fx{}
I have the following viewModel code in my Android Application
fun perform(operation: Action.Operation, sideEffects: (List<SideEffect>) -> Unit, render: (Reaction<String>) -> Unit): ...
3
votes
1answer
369 views
Where to do Arrow.io IO.runUnsafeSync() ? ViewModel or Activity/Fragment?
I'm trying to learn the Arrow library and improve my functional programming by transitioning some of my Android Kotlin code from more imperative style to functional style. I've been doing a type of ...
0
votes
1answer
184 views
Functional Programming short circuiting
I am investigating Functional Programming, namely Arrow-kt with Kotlin
my use case is as follows:
I want to perform an Action and return the associated Reaction
Both Action and Reaction have ...
1
vote
1answer
154 views
How to execute a program with Kotlin and Arrow
I'm trying to learn a bit of Functional Programming using Kotlin and Arrow and in this way I've already read some blogposts like the following one: https://jorgecastillo.dev/kotlin-fp-1-monad-stack, ...
3
votes
1answer
467 views
How to Implement “Railway Pattern” in Kotlin/Arrow.kt for producer Channel
I'm investigating Kotlin Coroutines & Channels in my current Android application.
I have the following code that manages remote Api calls and controls UI Side effects
private val historical: ...
0
votes
0answers
78 views
Using Klaxon for JSON with Arrow for Option in Kotlin?
Koltin newbie here. If I have a library with (Kotlin) Borrowers and Books and a Book is checked out when it has a Borrower (using Arrow's Option datatype):
data class Borrower(val name: Name, val ...
0
votes
1answer
2k views
How to write custom jackson deserializer in kotlin for Arrow's Option?
I need to de-serialize optional values from json to the data class in Kotlin, which have Option types. Example:
data class Sample(val id: Long, val content: Option<String>)
fun main() {
val ...
0
votes
1answer
48 views
ArrowKT - Lens invoke giving compilation error
I'm trying to follow this documentation about Lens in Arrow. However when I try to write a Lens
data class Player(val health: Int)
val playerLens: Lens<Player, Int> = Lens(
get = { player -...
2
votes
2answers
271 views
ArrowKT - @optics annotation not generating code
How do you setup the Arrow dependencies for @optics annotation to actually work? No companion objects are generated for the data classes annotated with @optics.
If I'm not mistaken, this is an ...
2
votes
1answer
214 views
Changing multiple attributes of a data class with a Lens
I am experimenting with Lenses in Kotlin, and I was wondering if there is an elegant way to change multiple attributes at the same time for one object. Let's say my domain looks something like this:
@...
1
vote
2answers
212 views
How to use IO compositions in arrow-kt within sync context
I have following interfaces:
interface UserRepository {
fun role(codename: String): IO<Option<Role>>
fun accessRights(roleId: Long): IO<List<AccessRight>>
}
Now trying ...