Questions tagged [arrow-kt]

Λrrow is a library for Typed Functional Programming in Kotlin

Related to the Arrow library for Kotlin. https://arrow-kt.io/

129 questions
3
votes
1 answer

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 MVI programming in the application to make testing…
3
votes
1 answer

What is Monad in kotlin arrow functional programming?

Can someone explain the concept of Monad in Arrow functional programming? https://arrow-kt.io/docs/datatypes/option/
Sujin Shrestha
  • 1,203
  • 2
  • 13
  • 23
2
votes
1 answer

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 following…
Albert Scholtz
  • 337
  • 3
  • 15
2
votes
1 answer

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 tuplize(f: (T, U) -> R): ((Pair) -> R) = { (a, b): Pair -> f(a, b) } val xs = listOf(Pair(1, 2), Pair(42, 23)) val f = tuplize(::foo) val…
Tobias Hermann
  • 9,936
  • 6
  • 61
  • 134
2
votes
2 answers

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 !! here is my code suspend fun…
Victor Orlyk
  • 1,454
  • 2
  • 15
  • 27
2
votes
2 answers

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 is next, so it is not compiling due to an error in…
Victor Orlyk
  • 1,454
  • 2
  • 15
  • 27
2
votes
1 answer

Is there any reason to use suspend fun fn(...): Either 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. So, according to the documentation, just using suspend we are converting our impure functions into pure…
codependent
  • 23,193
  • 31
  • 166
  • 308
2
votes
1 answer

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.
2
votes
1 answer

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 SpecificError2 : Error() } fun either2():…
Somaiah Kumbera
  • 7,063
  • 4
  • 43
  • 44
2
votes
2 answers

Cut pairs with empty values from map

I'd like to filter out all the pairs with empty values val mapOfNotEmptyPairs: Map = mapOf("key" to Some("value"), "secondKey" to None) expected: print(mapOfNotEmptyPairs) // {key=value}
2
votes
1 answer

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> = fx { request .pipe…
conceptacid
  • 248
  • 2
  • 13
2
votes
0 answers

Why use Kind instead of F

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 myFun(): Kind instead of fun myFun(): IO or fun myFun():…
user1713450
  • 1,307
  • 7
  • 18
2
votes
1 answer

Validate an object with Arrow-kt

I have an object (book), what fields should get updated by an event (author changed). Lets say the author field of the book only changes if the author has married and changed his name, but the book won't change if the author just moved to a new…
sschrass
  • 7,014
  • 6
  • 43
  • 62
2
votes
1 answer

Idiomatic Arrow

I have the following method: internal typealias MaybeError = Either override fun createCompany(companyDomain: CompanyDomain): MaybeError = checkCompany(companyDomain).map { it.toEntity() }.fold({…
m0skit0
  • 25,268
  • 11
  • 79
  • 127
2
votes
1 answer

Kotlin & Arrow.io: Transactions with IO.bracketCase

I am currently playing with Arrow.io in Kotlin and I would love to use the library (together with Spring Boot) in a project at work. One problem I don't quite know how to solve correctly is transaction management. IO.bracketCase(...) seems to me…
1 2
3
8 9