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…
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…
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…
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…
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…
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():…
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}
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…
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():…
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…
I have the following method:
internal typealias MaybeError = Either
override fun createCompany(companyDomain: CompanyDomain): MaybeError =
checkCompany(companyDomain).map { it.toEntity() }.fold({…
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…