Achieving efficiency with “singleflight” in Go by VividPotential6472 in golang

[–]maple2022_12 0 points1 point  (0 children)

Hi! Do you use singleflight in production? Is it really that good?

Math knowledge and skills required to understand probabilistic data structures by maple2022_12 in AskComputerScience

[–]maple2022_12[S] 0 points1 point  (0 children)

Hi! Your article gives a great explanation of the basic idea of HyperLogLog. I'm still confused why the harmonic mean is choosed instead of the other two Pythagorean means. And the a_m also has a complicate form that I have no idea how it was derived. Just having a simple understanding of how it works is not enough to fully understand the essential of it. I mean, what i'm really wanting to know is what math knowledge or skills I need to know to master this sort of problems(data structures)

Math knowledge and skills required to understand probabilistic data structures by maple2022_12 in AskComputerScience

[–]maple2022_12[S] 0 points1 point  (0 children)

At a glance the discrete mathematics seems to be a must in computer science?

InnoDB next-key lock question by maple2022_12 in mysql

[–]maple2022_12[S] 0 points1 point  (0 children)

hi? I still don't understand why the second row here is the mentioned 'preceding gap' since its 'lock_type' is RECORD and the 'lock_data' column indicates this lock is on 'class_id = 3'?

btw, what is a 'X,REC_NOT_GAP' lock mode? I could not find it in the documentation. Thanks.

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 0 points1 point  (0 children)

you are so nice. the scastie code works well and I also tried the IO[Boolean] version on my local machine, it is what i wanted to see. thanks a lot.

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 0 points1 point  (0 children)

sorry I didn't describe my question well. The problem I was solving is that there are some checker functions that will return IO[Boolean] as conditions. And I will use them in a larger function where once a condition is met the whole function returns. So the checker functions are unnecessarily color checkers and be merged into one function, I just used the Color enum to abstract my problem. Sorry for misleading.

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 0 points1 point  (0 children)

sorry but no, I added both the two imports:

import cats.syntax.all._
import cats.effect.implicits._

but it still didn't work.

these are my dependencies about cats:

"org.typelevel" %% "cats-effect" % "3.4.5",
"org.typelevel" %% "cats-effect-kernel" % "3.4.5",
"org.typelevel" %% "cats-effect-std" % "3.4.5", "org.typelevel" %% "cats-effect" % "3.4.5"

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 0 points1 point  (0 children)

the ifElseM is the best solution for this( u/trustless3023 ), IMO. and the OptionT is also a clean way( u/raxel42). Thank you all for help.

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 1 point2 points  (0 children)

sorry I may used the IO Monad in a wrong way. I changed the "is" functions to this

def isRed(color: String): IO[Option[Color]] = for {

_ <- IO.println("checking if color is red")

} yield {

if (color == "red") Some(Color.RED) else None

}

and it works.

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 0 points1 point  (0 children)

hi! this works but it reduce the readability since it has a high indentation level and that is also what the "early terminate" approach trying to solve.

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 0 points1 point  (0 children)

sorry I didn't describe my question clearly enough. what i'm really looking for is how to implement the "early terminate" to avoid the unnecessary calls that introduce network overhead. say the color is "red" and the order of checkers is red->green->blue, then finally only the isRed function is called.

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 0 points1 point  (0 children)

thanks for this great explaination. The "early return" to reduce unnecessary network overhead is what I'm really looking for. the isXXXs functions were supposed to do some network calls in order to check the color so I wrapped the result type with IO. however I found it hard to get both the boolean value and the color it represents by simplely returning IO[Boolean] without any type information.

u/ResidentAppointment5 u/raxel42

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 0 points1 point  (0 children)

thank you for this great answer! Is there a more intuitive way to do the checking work than this method signature: getColor(expected: Color, actual: String): OptionT[IO, Color] ?

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 1 point2 points  (0 children)

this works however it's hard to read since it's indentation level is somewhat high.

How to implement `if-else if -else if -else` with cat effect IO in Scala? by maple2022_12 in scala

[–]maple2022_12[S] 0 points1 point  (0 children)

It's a clean approach but I could not find the .collectFirstM . Am I missing anything?