Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • May 23 18:45
    i-walker commented #934
  • May 23 17:51
    nomisRev commented #2727
  • May 23 17:12
    christophejan opened #2727
  • May 23 16:01
    i-walker synchronize #2723
  • May 23 16:01

    i-walker on is-effect-overview

    rename traverseX and sequenceX … feat: contravariance for R, A i… Merge branch 'main' into is-eff… (compare)

  • May 23 15:01
    renovate[bot] edited #2568
  • May 23 15:01
    renovate[bot] edited #2709
  • May 23 15:00
    i-walker synchronize #2709
  • May 23 15:00

    i-walker on all

    feat: contravariance for R, A i… Merge branch 'main' into renova… (compare)

  • May 23 14:54
    i-walker synchronize #2726
  • May 23 14:54

    i-walker on is-deprecate-flatmap-map-eagereffect

    feat: contravariance for R, A i… Merge branch 'main' into is-dep… (compare)

  • May 23 14:29

    i-walker on is-contravariant-eager-effect

    (compare)

  • May 23 14:29

    i-walker on main

    feat: contravariance for R, A i… (compare)

  • May 23 14:29
    i-walker closed #2722
  • May 23 14:15
    i-walker review_requested #2709
  • May 23 14:15
    i-walker review_requested #2709
  • May 23 14:15
    i-walker review_requested #2709
  • May 23 13:33
    renovate[bot] synchronize #2709
  • May 23 13:33

    renovate[bot] on all

    Update all dependencies | data… (compare)

  • May 23 12:18
    i-walker review_requested #2726
Marcin
@marcincharezinski
mapOf("key" to Some("value"), "secondKey" to None) .filterValues { it is Some<String> } // or { it !is None } or { it.isDefined() } .mapValues { (_, v) -> (v as Some<String>).t }
Paco
@pakoito
filterMap(::identity) should do it
jim108dev
@jim108dev
Hi everybody! Is there any reference implementation for Arrow and Android which up to date and maintained?
Alexis Hernandez
@AlexITC
Is there any plan to get this fixed? I see there was a PR in the seperated ank repository which the main arrow repo doesn't have: arrow-kt/arrow#472
Rohde Fischer
@rfftrifork

so, I might be asking a trivial question, but for once my searching skills are failing me :/ so here goes:

I have val as: List<A> = TODO()
I have a val aToB: (a: A) -> Either<C, B>

what I want is to stop on the first error and return Either<C, List<B>>.

For now I have as.traverse(Either.applicative(), aToB).fix().map { it.fix() }

but isn't there a "cleaner" way to do this, so I don't have to call fix?

Paco
@pakoito
In 0.13 there will be a traverseEither for this, so you don't have to fix() it
specialised for Iterable and Either, which
Uriel Salischiker
@urielsalis
Hi! Im getting
'java.lang.Object arrow.core.Either$Left.getA()' java.lang.NoSuchMethodError: 'java.lang.Object arrow.core.Either$Left.getA()' at io.kotest.assertions.arrow.either.MatchersKt$beLeft$1.test(matchers.kt:72) at io.kotest.assertions.arrow.either.MatchersKt$beLeft$1.test(matchers.kt:65) at io.kotest.matchers.ShouldKt.invokeMatcher(should.kt:36) at io.kotest.matchers.ShouldKt.should(should.kt:31) at io.kotest.assertions.arrow.either.MatchersKt.shouldBeLeft(matchers.kt:63)
When trying to run tests, any ideas of what I might be missing?
on build.gradle.kts I have implementation("io.arrow-kt:arrow-core:0.13.1") implementation("io.arrow-kt:arrow-syntax:0.13.1") kapt("io.arrow-kt:arrow-meta:0.13.1")
Stojan Anastasov
@LordRaydenMK
You might wanna specify the Arrow version for test explicitly. Afik kotest also includes arrow transitively so you might get different versions on the classpath
Moritz Lindner
@linde9821_gitlab

HI :) I Want to work with a for comprehension for the Either monad.

According to "Functional Kotlin" i can do this by

 Either.monad().binding {
// ...
}.ev()

But this doesnt work

My workaround is to build the Couroutine with

runBlocking {
  either {
    //...
  }
}

But i dont think this is the way iam supposed to do this

Stojan Anastasov
@LordRaydenMK
You can use either.eagerfor pure, eager code
Moritz Lindner
@linde9821_gitlab
thx
I guess the example from "Functional Kotlin" is deprecated?
Stojan Anastasov
@LordRaydenMK
Yup, typeclasses were deprecated in 0.12 and removed in 0.13
Moritz Lindner
@linde9821_gitlab
Alright thank you :)
Kieran Simpson
@kierans
I'm a new player to Arrow, however I've done some FP work before in JS using Crocks. My current project is porting a JS library using Crocks to Kotlin so Arrow really grabbed my interest. However I couldn't find an easy "beginners guide" to Arrow. The documentation does talk a lot about Monads which is great, but I'm after other documentation like how to compose functions together, and write point free functions. After doing some digging I managed to use f compose g in my code. However why is compose an infix function? That's the sort of documentation I'm after, and I'm hoping someone can point me in the right direction. :)
Stefanqn
@Stefanqn
hi, is it possible to flatten a List<Option<T>>?
Sergei Zubov
@s-zubov
Hello! I'm new to ArrowKt :) I see that ArrowKt abandoned IO in favour of suspend () ->A. But I don't quite understand how to use it. For IO, a function that has a side effect wraps its return into IO<T>. And all callers to that function also wraps in IO, up to the end of the world. But how do I deal with the suspend () -> A approach with side effects that require inputs, i.e. fetching entity by ID from the DB? That function is suspend (ID) -> A, not suspend () -> A. As I understand from the reasoning behind switching to it from IO, using functions with input parameters can also work, but I'm unsure. Thank you :)
1 reply
Sergei Munovarov
@serhuz

Hello, I'm trying to update a list of items, where each item has a separate type, but some items share the same properties. It looks like this

sealed class Item

data class Ext1(val a: Int) : Item()
data class Ext2(val a: Int, val b: String) : Item()
data class Ext3(val b: String) : Item()

val items = listOf(Ext1(1), Ext2(1, "1"), Ext3("1"))

I'm trying to use a combination of a Traversal along with a Prism and some Lenses.

typealias ALens<S> = PLens<S, Item, Int, Int>

val ext1ALens = ALens(get = Ext1::a, set = Ext1::copy)
val ext2ALens = ALens(get = Ext2::a, set = Ext2::copy)

val aPrism = PPrism<Item, Item, ALens<in Item>, Item>(
    getOrModify = {
        when (it) {
            is Ext1 -> ext1ALens.right()
            is Ext2 -> ext2ALens.right()
            else -> it.left()
        }
    },
    reverseGet = ::identity
)

val traversal = PTraversal.list<Item>().modify(items) { item ->
    aPrism.modify(item) { lens ->
        lens.modify(item) { it * 2 }
    }
}

The problem is that I can't make getOrModify right. Is it possible to define a generic lens that will be able to handle different subtypes of Item?

Moritz Lindner
@linde9821_gitlab

I have a short question regarding traverse in arrow. as far as I am aware since 0.13.1 traverse is now directly implemented like with traverseEither and does no longer work with typeclasses because of their deprecation.

However, I cannot find an implementation for traverseOption and had to write my own.

Is there a reason for this or was I just unable to find an implementation?

I would also be interested in some feedback regarding my implementation
// map2 is actually copied from https://www.manning.com/books/functional-programming-in-kotlin
    private fun <A, B, C> map2(
        oa: Option<A>,
        ob: Option<B>,
        f: (A, B) -> C
    ): Option<C> =
        oa.flatMap { a ->
            ob.map { b ->
                f(a, b)
            }
        }

    private fun <A, B> List<A>.traverse(
        f: (A) -> Option<B>
    ): Option<List<B>> {
        return this.map(f).fold(Option(emptyList())) { acc: Option<List<B>>, option: Option<B> ->
            map2(
                acc,
                option
            ) { list: List<B>, b: B ->
                list + b
            }
        }
    }
Shane
@sdrafahl
Hey, I was looking to use Kind from Arrow in a new Android project. However arrow.Kind is not valid. It can use the other Arrow types like Either or Option. I added this to my build.gradle implementation "io.arrow-kt:arrow-fx-coroutines:0.13.2". I was kind of wondering if the higher kinded stuff is in some other package?
Moritz Lindner
@linde9821_gitlab
@sdrafahl as far as I know the higher kinded stuff was removed since 0.13.0 as Arrow is only supposed to be an functional extension library. https://www.47deg.com/blog/arrow-0.13.0-release/
Łukasz Milunas
@Milunas

Hi, I have problem while trying to use Monad Comprehension with ArrowKt Core.

    fun create(order: Order): Either<OrderError, Order> = either.eager {
        val something = fetchSomething(order.id).bind()
        val mapped = order.map(something).bind()
        val stored = orders.save(mapped)
        stored
    }

Everything is fine except that this function returning order and not stored. :/

Stojan Anastasov
@LordRaydenMK
assuming orders.save returns an Either<OrderError, Unit> you are missing a .bind()
Łukasz Milunas
@Milunas
Hi @LordRaydenMK , thank you for response. :)
My function as you can see returning Either<OrderError, Order> because I want to return mapped and stored object. Unfortunately it is compiling but returning order that was passed to fun.
Where should I add bind()? After orders.save(mapped)?
Stojan Anastasov
@LordRaydenMK

@Milunas yup, orders.save(mapped).bind(). Functions that return Either need a bind().

if that doesn't fix it, I would need more function signatures/types to help

Łukasz Milunas
@Milunas

I wrapped this in Either.Right(orders.save(order)).bind() but result is the same. How can I provide you more function signatures/types?
I'm using Spring and invoking this either.eager like that:

@PostMapping
    fun add(@RequestBody order: Order): ResponseEntity<*> = handler.create(order)
            .map { ResponseEntity.status(201).body(order) }
            .getOrHandle { ResponseEntity.status(it.status).body(it.message) }

Can be this somehow causing trouble?

Stojan Anastasov
@LordRaydenMK
@Milunas what's the function signature of orders.save()? and is the type of mapped Order?
Łukasz Milunas
@Milunas

@LordRaydenMK orders.save is just Spring MongoDB Repository method with signature <S extends T> S save(S entity);

interface OrderRepository: MongoRepository<Order, String> {

mapped Order is Order type (mapped is a copy method with additional fields)

Stojan Anastasov
@LordRaydenMK

@Milunas in that case ignore my comment about bind() (because save does NOT return an Either).

If the function returns an Order it means it's not failing.... you can try adding logs to see if order.map(something) works as expected

Łukasz Milunas
@Milunas
Yes, order.map(something) works as expected and even orders.save(mapped) works fine. Mapped object is stored in database. But function create returning order that was passed to function instead of stored.
Łukasz Milunas
@Milunas
Maybe I'll try to reproduce this in some small project and post url to repo over the weekend.
harrydevnull
@harrydevnull
Hi I'm new the kotlin arrow .. I was trying to convert parts of java service into kotlin ...
I have to do. a series of operation sequentially and I modeled every function as Either<DomainError,A>
I finally got a structure similar to below and I intend to use the monadic flow for that ..
but I read some where IO is deprecated..
so I'm left with something like this .. Is there a better way to solve this?
 val o: List<Either<DomainError, List<Policy>>> = domainObjects.map { ev ->
            getConfigVersion(configId, versionId).flatMap { piConfigVersion ->
                isEditable(piConfigVersion).flatMap { validatedPiConfigVersion ->
                    addOrUpdateIncidentAction(validatedPiConfigVersion, ev).flatMap {
                        updateScriptBehaviourPolicies(validatedPiConfigVersion, ev)
                    }
                }
            }    
        }

`
harrydevnull
@harrydevnull
I managed to change to
     either.eager<DomainError, List<Policy>> {
                val piConfigVersion = getConfigVersion(evRequest.configId, evRequest.versionId).bind()
                val isEditable = isEditable(piConfigVersion).bind()
                val incidentAction = addOrUpdateIncidentAction(piConfigVersion, evRequest.ev).bind()
                val updatedIncidentAction = saveIncidentActions(incidentAction).bind()
                val policies = updateScriptBehaviourPolicies(piConfigVersion, evRequest.ev).bind()
                val updatedPolicies = savePolicies(policies).bind()
                updatedPolicies
            }
can I refactor this any further ?
using Kleisi?
ovu
@ovu
Hi all, I am using the version 1.0 of arrow, however I do not find the integration with reactor, where can I find it? Or was a decision to drop the integration with reactor?
Carlos Anjos
@anjosc
Hi there ! I've been using the NonEmptyList, but I can't find an equivalent NonEmptySet that would be handy. Any plans to provide one ?
larsw
@larsw
Hi, I've taken a dependency in my Maven-based project on io.arrow-kt:arrow-core:1.0.1 . I've restored the dependencies, but when I try to import arrow.core.Either I'm getting an error that says Kotlin: Unresolved reference: Either
Somaiah Kumbera
@somaiah
Hey I have the same problem as @larsw . I just assumed the mvn jar was corrupt on my server. Is there a resolution for this?
Somaiah Kumbera
@somaiah
FYI @larsw arrow-kt/arrow#2658
Jonas Adler
@jadlr

Hi all, I'm having trouble achieving something using Prisms. Is there a version of .modify() that let's me transform into another type?
Consider this simple example:

@optics
sealed class State{
    companion object {}
    data class Response(val msg: String?): State()
    object Error: State()
}

// this does not compile
State.response.modify(State.Response(null)) { response ->
    if (response.msg == null) {
        State.Error
    } else {
        response
    }
}

Is there a function that let's me do type transformation when modifying? Thanks!

Jonas Adler
@jadlr

Got it :blush:

State.response.getOrModify(State.Response(null)).fold(::identity) { response ->
    if (response.msg == null) {
        State.Error
    } else {
        response
    }
}

Love the lib so far :thumbsup: Thanks!

Jacky-YC
@Jacky-YC
Iso generation is supported for data classes with up to 22 constructor parameters. this why?
antunonline
@antunonline
Hi guys. I have a question regarding arrow-core and ValidatedNel. How can I combine two ValidatedNel objects?
antunonline
@antunonline
I think that I have found the way to combine ValidatedNel's but the example shown in url(https://arrow-kt.io/docs/apidocs/arrow-core/arrow.core/and-then.html) does not work when I run it locally with arrow-core:1.0.0. andThen is not found.