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…
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("""
…
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…
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):…
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 {
…
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…
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…
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…
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…
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 =…
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…
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…
Given the following functions:
context(Raise)
suspend fun getUser(legalId: UserLegalId): User
context(Raise)
suspend fun getDepartment(departmentCode: DepartmentCode): Department …