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
28
votes
3 answers

Why use Arrow's Options instead of Kotlin nullable

I was having a look at the Arrow library found here. Why would ever want to use an Option type instead of Kotlin's built in nullables?
pavlos163
  • 2,730
  • 4
  • 38
  • 82
10
votes
2 answers

Kotlin - Infer type for one of two generic parameters

I am trying to create a function that has two generic types: one reified, and another derived from the context of its usage (since it is an extension function): inline fun Either.bypassLeft(transformation: Throwable.()…
10
votes
1 answer

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 = 1.right() I tried something like below but it shrinks the scope…
Vencat
  • 1,272
  • 11
  • 36
8
votes
1 answer

Which should we choose between Effect and Either as a return type of our business services?

With the arrival of Arrow 1.1.x we got the new Effect class. Up to now, my business classes returned Either to model the effect of returning an error or a value, e.g.: @Service class CreateDepartmentUseCaseImpl( private val…
codependent
  • 23,193
  • 31
  • 166
  • 308
8
votes
2 answers

How do I create my own data type with Arrow

What are the steps to create my own data type when using arrow. It's simple to use something like Option with the provided extension constructors like Some(data) or None. However, how can I create my own data type that has functional operators like…
pablisco
  • 14,027
  • 4
  • 48
  • 70
7
votes
2 answers

Kotlin's Arrow Either and transactions

I am trialing the use of Kotlin's Arrow library Either object to handle exceptions within a project. My experience with it thus far has been OK, but I'm struggling to find a way to handle transactions with Either - and specifically rollbacks. In…
edu
  • 428
  • 2
  • 10
7
votes
1 answer

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 cartesianProduct(xs: List, ys: List): List
Chris
  • 408
  • 2
  • 10
7
votes
1 answer

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 relevant APIs are now concrete over the data…
Luca Piccinelli
  • 379
  • 1
  • 17
6
votes
1 answer

How to typesafe reduce a Collection of Either to only Right

Maybe a stupid question but I just don't get it. I have a Set> and want to output a Set with Arrow-kt.
sschrass
  • 7,014
  • 6
  • 43
  • 62
6
votes
1 answer

For comprehensions with kotlin and arrow-kt library

I use arrow-kt library and I'm trying to employ Either and IO within the same for comprehension. Say I have the next piece of code: IO.monad().binding { val ans: Either = someFunctionThatReturnsEitherWrappedInIO().bind() } Now, I'd…
MaxG
  • 1,079
  • 2
  • 13
  • 26
6
votes
1 answer

Why would validation break the monad laws?

On SO an explanation is given why a Validation like in scalaz, cats (Scala), or Arrow (Kotlin) can't be a monad. As far as I understand it's because they've modelled monads in terms of applicative functors and the desired behaviour of a Validation…
Jan Bols
  • 457
  • 4
  • 11
5
votes
2 answers

Relation between Arrow suspend functions and monad comprehension

I am new to Arrow and try to establish my mental model of how its effects system works; in particular, how it leverages Kotlin's suspend system. My very vague understanding is as follows; if would be great if someone could confirm, clarify, or…
Ulrich Schuster
  • 1,670
  • 15
  • 24
5
votes
3 answers

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 using a convert function. Let's also say that this…
Chris
  • 87
  • 2
  • 7
5
votes
1 answer

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: @optics data class Parameters( val duration:…
Mario F
  • 45,569
  • 6
  • 37
  • 38
1
2 3
8 9