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
1
vote
1 answer

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, which is good, I've understand the main idea, but…
Dina Bogdan
  • 4,345
  • 5
  • 27
  • 56
1
vote
2 answers

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) fun main() { val mapper = ObjectMapper() val v1 = mapper.readValue(""" …
Izbassar Tolegen
  • 1,990
  • 2
  • 20
  • 37
1
vote
2 answers

How to use IO compositions in arrow-kt within sync context

I have following interfaces: interface UserRepository { fun role(codename: String): IO> fun accessRights(roleId: Long): IO> } Now trying to use it to compose effectfful operations like this: private fun…
Izbassar Tolegen
  • 1,990
  • 2
  • 20
  • 37
1
vote
1 answer

Kotlin arrow-kt missing flatMap on Validated and ValidatedNel

I am really struggeling with the Validated types of the arrow library. What I don't get is: why is there no flatMap or flatten when working with Validated? I am coming from the "Either world" where this is no issue at all. But I need multiple errors…
Zordid
  • 10,451
  • 11
  • 42
  • 58
1
vote
1 answer

Kotlin arrow.kt - Option.getOrElse is accepting other type than T

I am trying to use the Option.getOrElse() method. According to the source: inline fun fold(ifEmpty: () -> R, ifSome: (A) -> R): R = when (this) { is None -> ifEmpty() is Some -> ifSome(t) } fun Option.getOrElse(default: () -> T):…
Raghavendra
  • 5,281
  • 4
  • 36
  • 51
1
vote
1 answer

Kotlin arrow validated list of errors

I want to validate multiple fields of a Person and return a Validated object with all related errors. I use kotlin version 1.3.41 and arrow 0.8.2. I have the following classes: class Person(id: Long, name: String) sealed class PersonError { …
ielkhalloufi
  • 652
  • 1
  • 10
  • 27
1
vote
1 answer

FlatMapping ListK and Option

I can't flatmap a ListKOf with T -> Option. e.g. listOf(1,2,3).k().flatMap { i -> if (i % 2 == 0) Some(i) else None } Reports Required (Int) -> ListKOf. Found (Int) -> Option. To make it compile I need to do…
Synesso
  • 37,610
  • 35
  • 136
  • 207
1
vote
1 answer

Unable to generate objects for both @higherkind and @extension

I define two objects: data class ParserK annotated with @higherkind interface ParserKFunctor annotated with @extension Here is the code: @higherkind data class ParserK(val f: (String) -> Option): ParserKOf { companion…
neshkeev
  • 6,280
  • 3
  • 26
  • 47
1
vote
1 answer

Difficulty using arrow-kt Either, Option, and RxJava together

I'm having a lot of difficulty figuring out a good way to coordinate using RxJava along with the arrow-kt Either and Option types. I have two methods that both return Single class Foo(val qux: Option) class Bar class…
1
vote
1 answer

What the difference between filterOrElse and filterOrOther from Arrow?

I could not find the difference between filterOrElse and filterOrOther The signature of filterOrElse is inline fun EitherOf .filterOrElse(predicate: (B) -> Boolean, default: () -> A): Either and filterOrOther is inline fun
Bukharov Sergey
  • 9,767
  • 5
  • 39
  • 54
1
vote
1 answer

How can I use Arrow-kt's Some() in Groovy code?

I'm trying to test my Kotlin code, which has Arrow-kt types, using Spock in Groovy. However, I'm not able to use Arrow-kt's additions such as Some. For example, I have a test as follows: @Unroll def "add returns #expected for queryRecord…
Ayberk
  • 410
  • 10
  • 21
1
vote
1 answer

ClassCastException when using arrow-kt's list comprehension

I am trying to use a list comprehension with a guard in Kotlin. When I run the following code, I get a ClassCastException where none seems to be relevant. data class CharWrapper(val value: Char) @Test fun `isolate bug`() { val wrappedChars =…
0
votes
0 answers

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 make "exhaustive when" confusing for error handling? Would it be…
0
votes
1 answer

Mocking a service that uses a context receiver Raise 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() with a context receiver of…
codependent
  • 23,193
  • 31
  • 166
  • 308
0
votes
1 answer

How can we use context receivers and Arrow 1.2.0 parZipOrAccumulate? No required context receiver found: Cxt

Given the following functions: context(Raise) suspend fun getUser(legalId: UserLegalId): User context(Raise) suspend fun getDepartment(departmentCode: DepartmentCode): Department …
codependent
  • 23,193
  • 31
  • 166
  • 308
1 2 3
8 9