Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 17 19:02
    LordRaydenMK edited #378
  • Jan 17 19:01
    LordRaydenMK ready_for_review #378
  • Jan 17 19:00
    LordRaydenMK synchronize #378
  • Jan 17 10:17
    LordRaydenMK commented #377
  • Jan 17 10:09
    LordRaydenMK edited #378
  • Jan 17 09:58
    LordRaydenMK synchronize #378
  • Jan 16 18:30
    rachelcarmena commented #377
  • Jan 16 16:57
    LordRaydenMK opened #378
  • Jan 16 13:41
    i-walker assigned #327
  • Jan 16 13:41
    i-walker unassigned #328
  • Jan 16 13:40
    i-walker assigned #328
  • Jan 16 09:20
    LordRaydenMK commented #377
  • Jan 16 08:52
    LordRaydenMK edited #377
  • Jan 15 19:10
    LordRaydenMK opened #377
  • Jan 15 16:46
    franciscodr synchronize #90
  • Jan 15 16:46

    franciscodr on sv-poc-unkind-optics

    Replace Traversal with Every in… (compare)

  • Jan 15 16:22
    danimontoya review_requested #300
  • Jan 15 16:22
    danimontoya opened #300
  • Jan 15 16:21

    danimontoya on dm-disconnect-incubator-check

    Remove optics-mtl from docs (compare)

  • Jan 15 16:07
    danimontoya review_requested #299
Andrei Bechet
@anbe_gitlab
Thank you for your answer. I had the same feeling and already conveyed it. I hope it goes through as I really enjoy using it and have been trying to show others about it.
Simon Vergauwen
@nomisRev
Very happy to hear you're enjoying using it!
Thanks for using and promoting Arrow!
sarna
@sarna
hey, I believe you have a typo on the main page (arrow-kt.io)
when you hover over “arrow optics” you have an employee “john” whose name is “Audrey Tang”
if you click on “arrow optics” and go to the docs, john is john - no mention of Audrey :)
Marty Pitt
@martypitt_gitlab

Hi. Fairly new to Arrow and FP (though suspect I've been using them long enough to cement in some bad habits :)

I'm curious what the correct way is to combine two Eithers

ie

val thingOne : Either<A,B> = ...
val thingTWo : Either<A,C> = ...

How to I combine these such that if both are right, I get { B, C } , otherwise I can somehow comibne A's?

Bob Glamm
@glammr1
@martypitt_gitlab That strikes me as Validation, not Either
Validation is a type that combines errors (left side) when any validation fails and creates a product type out of the right side when all succeed
Marty Pitt
@martypitt_gitlab
Hi @glammr1 -- Thanks very much, I'll check that out!

One more newby question -- on the website, I see a nice succinct syntax:

suspend fun prepareLunch(): Either<CookingException, Salad> =
    either<CookingException, Salad> {
        val lettuce = !takeFoodFromRefrigerator()
        val knife = !getKnife()
        val lunch = !prepare(knife, lettuce)
        lunch
    }

What's the ! doing here, and how can I learn more about it? (I'm assuming it's not a normal not operator?)

Bob Glamm
@glammr1
Correct, ! is an alias for .bind()
IIRC the above is roughly equivalent to takeFoodFromRefrigerator.flatMap { lettuce -> getKnife.flatMap { knife -> prepare(knife, lettuce).map(lunch) } }
Gerard Bosch
@gerardbosch
Is the above like a for-comprehension?
Bob Glamm
@glammr1
yeah, the following is rough Scala equivalent:
for {
  lettuce <- takeFoodFromRefrigerator()
  knife <- getKnife()
  lunch <- prepare(knife, lettuce)
} yield lunch
Leonid Vygovskiy
@leonidv

Hi all! I have a method, which loads a user from the database by id

data class User(val id : String, val displayName : String)
fun load(id : String): Either<Exception,Option<User>>

data class Member(val userId : String, val name : String) {
 companion object {
  fun of(user : User) : Member = Member(user.id, user.name)
}

I have usersIds = listOf("1","2","3") which I should convert to members list. Any good solution? My variants are very-very terrible

Bob Glamm
@glammr1
Presumably Option<User> is if the user isn't found in the DB. What do you want to have happen if Exception occurs for any user ID?
Leonid Vygovskiy
@leonidv
Hi Bob! If there is one Left<Exception> in the list, the operation is failed. If Option<User> is None, it is omitted.
listOf(Left<Exception>,Right(Some(User)),Right(None)) => fail
listOf(Right(Some(User(id="1")),Right(None)) => List(Member(id="1"))
Paco
@pakoito
usersIds.traverse(OptionT.applicative(Either.applicative())) { load(it) }
maybe something like that
May be EitherT and Option inside
you can also do each step manually
userIds.traverse(Either.applicative()) { load(it) }.map { it.filterMap(::identity) }
Davide Bertola
@davibe
Hi
I have seen a talk where the guy used fx { ... }
but it does not seem to work for me
Screenshot 2020-11-01 at 15.58.52.png
this is what I am currently using instead, but I do not like the strikethrough on fx there
Paco
@pakoito
IO.fx
oh, no, I see
yes, don't use async() here, just use IO(Dispatchers.IO) { print("") }
Cody Mikol
@codymikol
Does anyone know how to convert a Flux / Mono into an Either? The documentation refers to .k() extension in arrow-fx, but I can't seem to find that in the 0.11 build
Cody Mikol
@codymikol
aha, I see its a separate package arrow-fx-reactor
Rohan Sircar
@rohan-sircar
Wonder how that works seeing as Flux/Mono are async types whereas Either is a synchronous type
Cody Mikol
@codymikol
@rohan-sircar I had a misunderstanding of what .k() actually accomplishes. It doesn't allow you to use Either, but rather allows you to benefit from monad comprehensions in arrow-fx.
I'm pretty new into all of this, still trying to get my bearings :P
Rohan Sircar
@rohan-sircar
@codymikol It's okay. In case you're still wondering, in general you cannot go from an async type to a sync type without blocking a thread, which is discouraged and error prone. In FP async types are modelled as monads so you use combinators like map, flatmap and filter to work with them.
With Either though it would become a Future[Either[L,R]] though, so you lose the either's behavior. To get it back you use monad transformers like EitherT or a bifunctor async type i.e. Future[L,R] which are kind of a recent thing.
Angelo Sciarra
@eureka84
Hello guys, I was trying to play around with State monad this afternoon but I was not able to find the state {} computation block (something similar to either { !e1 + !e2} being e1 and e2 two Either<E, Int>). What am I missing? (using arrow 0.11.0)
Angelo Sciarra
@eureka84
to answer my question the computation block is still reachable via State.fx(idMonad) { }
I have another question, I guess also this one is a bit silly, anyhow: once upon a time I could manage to obtain an Id monad via Id.monad, but right now (v 0.11.0) it says it is deprecated and it is going to be removed. I see there is instead an Interface IdMonad but I don't understand what am I missing to get an instance of it (I just declared val idMonad = object: IdMonad {} but I feel like there should be a better way)
>>=
@fommil

is a recent run of https://github.com/arrow-kt/arrow-fx/tree/master/arrow-benchmarks-fx available anywhere?

Failing that, does anybody know a) how to run it b) roughly how long it takes to run?

>>=
@fommil
typing gradle jmh in that dir gets me a Caused by: javax.lang.model.type.UnknownTypeException: Unknown type: "none" at com.squareup.kotlinpoet.TypeName$Companion$get$1.visitNoType(TypeName.kt:187)
>>=
@fommil
trying again with java 8, I get a compilation error
bazpiyo
@bazpiyo
hi all!!
I have a question
how to ".bind()"
val value: OptionT<EitherTPartialOf<Throwable, ForListK>, String> =
  OptionT.fx(EitherT.monad<Throwable, ForListK>(ListK.monad())) {
    "?????"
 }
Paco
@pakoito
Oh jesus
that's an ugly monad stack
listOf(Right(Some("1"))).bind()
that should give you a String