by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 09:06
    nomisRev synchronize #226
  • 09:06

    nomisRev on sv-flaky-test-hunt

    Take middle of old and new iter… (compare)

  • Jul 09 18:46
    nomisRev synchronize #226
  • Jul 09 18:46

    nomisRev on sv-flaky-test-hunt

    Increase ArrowFxSpec iterations (compare)

  • Jul 09 17:27
    nomisRev synchronize #226
  • Jul 09 17:27

    nomisRev on sv-flaky-test-hunt

    Increase iterations Arrow Fx Qu… (compare)

  • Jul 09 15:46
    aballano review_requested #185
  • Jul 09 15:46
    aballano review_requested #185
  • Jul 09 15:46
    aballano review_requested #185
  • Jul 09 15:46
    aballano synchronize #185
  • Jul 09 15:46

    aballano on rework-fx-constructors

    Rename fx constuctors to avoid … (compare)

  • Jul 09 13:07
    rachelcarmena commented #2174
  • Jul 09 13:07
    rachelcarmena commented #2174
  • Jul 09 13:06
    rachelcarmena synchronize #2174
  • Jul 09 13:06

    rachelcarmena on additional-documentation

    Add link for the badge (compare)

  • Jul 09 13:05
    aballano opened #185
  • Jul 09 13:03
    rachelcarmena commented #2174
  • Jul 09 13:02
    rachelcarmena review_requested #2174
  • Jul 09 13:02
    rachelcarmena opened #2174
  • Jul 09 13:02

    rachelcarmena on additional-documentation

    Documentation - Re-organize th… (compare)

Cesar Tron-Lozai
@cesartl
@raulraja I want to make a PR to add exponentiation by squaring to Arrow as you suggested. I'm guessing this should go into arrow-core? Could you recommend where in the project this algorithm could go? Some sort of MonoidUtils file?
Paco
@pakoito
is it like...a new typeclass?
ExponentialMonoid?
Cesar Tron-Lozai
@cesartl
sorry @pakoito week at work was busy. I don't think it's a new typeclass. It's a method that can be used on any existing monoid.
Paco
@pakoito
oh, gotcha
so, straight into Semigroup it goes then!
Roman Tkalenko
@tkroman
Hi. Is there a way to create a lens for a generic data class? I.e. data class X(x: Int); data class Foo<A>(a: A), then Foo<X>.a.bar?
Christopher Sabater Cordero
@cs-cordero
Hi everyone, new to Kotlin, new to Arrow, new to FP. I'm reading the docs about Arrow Fx here https://arrow-kt.io/docs/0.10/fx/#turning-side-effects-into-pure-values-with-effect and I was wondering whether someone can explain to me something.
How exactly is it that we can consider effect { sayHello() } a "pure value"? I get that it returns an IO object and is lazily evaluated, but won't it still cause a side effect when eventually evaluated?
Bob Glamm
@glammr1
Yes, it will eventually cause a side-effect when evaluated, but that should happen at the "edge of the world"
Well constructed FP programs look something like the following:
(a) Summon required instances (usually parameterized over IO at the top level, but could be Rx or coroutines in the case of Android or interop with other systems)
(b) Construct computations by composition of lazy functions over effects. A better example might be effect { doSql("INSERT INTO xx (yy) VALUES ($zz)") }.flatMap { (rowsInserted) -> ... }, which says "here's a function that inserts something into a table. Given that I have that function, give me another function that not only inserts something into the table but also does something based on the number of rows inserted. So computations are constructed entirely by function composition. effect { sayHello() } essentially gives me a function I can compose but not run yet.
So that's pure/referentially transparent because it is only a function, not a side-effect that occurs.
Bob Glamm
@glammr1
(c) Once all computations are constructed, run the entire construction with a call to a single "unsafe" function. On IO this is usually unsafeRunSync, but for simpler types like Option this is something as trivial as get or getOrElse.
So the whole goal of FP program construction is to build compositions of functions/effects and then have a single call that causes the effects to be evaluated. What ends up happening is that smaller FP programs are being constructed inside of larger FP programs as effects are evaluated. (This is necessary to enable conditional execution of effects)
The nice property about this is that the contract is explicit: if you write a function that takes a (Int, String) and produces a IO<Unit> you can replace that function with anything with that type signature and it will "just work" within the confines the contract: IO is an effect that sequences computations (Monad) and captures errors (MonadError). (IO also has a number of other typeclasses it inherits from enabling it to be used to create programs that operate in parallel over fibers/coroutines/threads/etc.)
Bob Glamm
@glammr1
Also, as an additional 2 cents: I'd recommend actually writing programs using Kotlin/Arrow or Scala/Cats + Cats Effect or Haskell to really get the feel for it. There are a lot of terms used that originate from category theory; don't hesitate to ask for a conceptual meaning of them, there are lots of friendly people willing to help answer them. I found I had to pull information in from a lot of different places to get even a basic handle on it.
Learning concepts in one or more of them will translate to the others readily.
Finally, I'd recommend joining #arrow on kotlinlang.slack.com
That channel generally has more people present available to answer questions more of the time.
QP
@theqp
Hello
Does it make sense to try to write a library like Arrow.kt for Java?
Is there a missing language feature which makes this not viable?
Philippe Bastiani
@PhBastiani
Same limitation: emulated HKT. Require additional boilerplates... But doable. See
https://github.com/aol/cyclops
QP
@theqp
thanks, I knew about cyclops, but cyclops-pure is new to me
Erik Dreyer
@edreyer
I think this may be the most promising new entrant for FP in Java: https://palatable.github.io/lambda/
breucode
@breucode

Hi guys, I am pretty new to FP and have a question regarding Kleisli:
Basically I want to pass a context down to the db access layer, but I want to access this context everywhere in between. So as an example I have this:

object OrderRepository {
    fun findAll(userId: String): Kleisli<Context, ForIO, List<Order>> =
        Kleisli { ctx ->
            IO {
                ctx.db.query("someQuery")
            }
        }
}

object OrderService {
    fun findAll(userId: String): Kleisli<Context, ForIO, List<OrderResponse>> =
         OrderRepository.findAll(userId).map(IO.monad()) { orderList ->
            orderList.map {
                //Create OrderResponse from Order
            }
        }
}

The OrderService calls the OrderRepository in this case. This examples works fine, but my problem is, that I don't know how to access the context in the OrderService (findAll) function. Can you tell me how to do that, or doesn't this make sense at all? Thanks in advance for your help.

QP
@theqp
@edreyer too bad it does not have IO.
Srki Rakic
@unaryops
I have REST controller endpoint that executes command handler that is wrapped in IO.fx (snippet below). I'm changing the return type of a commandFrom(commandType, command) from Command to Either<InvalidCommand, Command>. I'm struggling with finding the best way to tie these together with this change. Any feedback is welcome. Thank you.
    return commandHandler.handle(commandFrom(commandType, command))
      .attempt()
      .map { result -> result.fold({ Response.Error(it.toString()) }, { Response.Success(it) }) }
      .unsafeRunSync()
Srki Rakic
@unaryops
It could be also a commandFrom(commandType, command) : IO<Either<InvalidCommand, Command>>
Srki Rakic
@unaryops
Hm... I think this may work. Can you comment if this is the right approach.
    return EitherT.monad<ForIO, DomainError>(IO.monad()).fx.monad {
      val command = EitherT(commandFrom(commandType, command)).bind()
      EitherT(commandHandler.handle(command).map { it.right() }).bind()
    }.value().fix()
      .map { result -> result.fold({ Response.Error(it.toString()) }, { Response.Success(it) }) }
      .unsafeRunSync()
And if it's the right approach, can someone please break down the following piece of codeEitherT.monad<ForIO, DomainError>(IO.monad()).fx.monad. I have a very hard time understanding it.
Jem Mawson
@Synesso
Hi. I am using Reader in a team mostly familiar with imperative programming. I keep getting questions about the Id Monad when mapping Readers. To be honest I'm not sure why it's needed. Can it be elided somehow?
Bob Glamm
@glammr1
@unaryops EitherT.monad<ForIO, DomainError>(IO.monad()) summons the correct EitherT instance for the comprehension. .fx.monad begins the comprehension.
@Synesso Reader is isomorphic to a function call, so strictly speaking it is not needed :)
Srki Rakic
@unaryops
@glammr1 thank you. One thing I've noticed that this line EitherT.monad<ForIO, DomainError>(IO.monad()) breaks in 0.10.5 version of the library. Specifically, it doesn't like the IO.monad() type. The snippet above works on version 0.10.3
In 0.10.5 it's expecting MF: Monad<DomainError> and in 0.10.3 MF: Monad<ForIO>. Do you think this is a bug or intentional change between the two version?
Bob Glamm
@glammr1
I am unfortunately not familiar with the details of changes between 0.10.3 and 0.10.5. The people in the #arrow channel at kotlinlang.slack.com may have those answers. (That channel has much more activity than this Gitter channel does, and you may receive more timely and accurate answers to your questions there.)
Srki Rakic
@unaryops
Ah, gotcha. Thanks again. I'll try there.
Is that slack channel open for everyone?
Bob Glamm
@glammr1
It should be. If it is not let me know and I'll inquire in the channel
Jem Mawson
@Synesso
Will head to slack also. @glammr1 It shouldn't be needed, but syntactically is. Is that something we'll see removed from the api at some stage?
Bob Glamm
@glammr1
@Synesso That's a question for the #arrow devs :)
jaka
@jakalal4_twitter
hey there, I followed arrow's config from github, and gradle build succesful, but when I import arrow.* , intellij idead tell me that arrow is not resolved, here is the gradle config https://paste.ubuntu.com/p/znWcb9BcDn/
ovu
@ovu

Hi all, I am using Validated as you can see in the following code:

            return aList
                    .traverse(ValidatedNel.applicative(Nel.semigroup<ValidationError>()), ::validate)
                    .fix()
                    .map{
                        it.fix()
                    }

the code does what I expect, however I am asking is there is a better way to write it to avoid the two time fix() function calls. I understand it returns a Kind<NotEmptyList<ValidationError>, Kind<ForListK, MyModel>>. Any recommendation?

Bob Glamm
@glammr1
If I understand correctly the next major release will not require .fix
ovu
@ovu
Is there any documentation about it? Which is going to be the new major version?
Bob Glamm
@glammr1
0.11.0 or 1.0, not sure
head over to #arrow in kotlinlang.slack.com , the devs are there and generally are good about answering questions
ovu
@ovu
Great! Thanks for the information!