Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Giuseppe Cannella
@gekomad
it works :thumbsup: :thumbsup: thanks
satyagraha
@satyagraha
are there any guarantees that .traverse executes strictly left-to-right? I am thinking of someList.traverse(someFunctionReturningAFuture(_)) which I suspect becomes something like someList.map(someFunctionReturningAFuture(_)).sequence which isn't what I want. Ideas? possibly some kind of foldLeft?
Luis Miguel Mejía Suárez
@BalmungSan

@satyagraha

"are there any guarantees that .traverse executes strictly left-to-right? I am thinking of"

The results are combined / evaluated in sequential order if the type in question is a Monad
However, that is all, since Futures run whenever they want and we can't control them cats can't give you guarantees about it.

If you use IO instead then yeah, it will be sequential.
satyagraha
@satyagraha
@BalmungSan makes sense, thanks
eason du
@doofin

Hi ,I am wondering why this does or doesn't type check about free monad(it does work for the tutorial's freemonad case ) :

  def impureCompilerId: DslStoreA ~> Id =
    new (DslStoreA ~> Id) {
      val kvs = mutable.Map.empty[String, Any]

      override def apply[A](fa: DslStoreA[A]): Id[A] = {
        val r = fa match {
          case UpdateVar(v, value)                => ???
        }
        r
        ()
      }
    }

which errs that found : Unit [error] required: cats.Id[A]

Luis Miguel Mejía Suárez
@BalmungSan
@doofin you may want to ask in discord instead: https://discord.gg/XJkubMZE
eason du
@doofin
Thanks! I have reposted there
Timo Meijer
@TimoMeijer
Is it possible to define multiple Functors for the same datatype? The usecase is a datatype that makes sense to map over in multiple type arguments
steve-e
@steve-e
Hi, https://typelevel.org/cats/ is a 404 for me at the moment. (I put a message on discord already)
Martijn
@martijnhoekstra:matrix.org
[m]
I'm using monadThrow, and I'd like to do something like ensure, but in F, i.e. def ensureF(t: => Throwable)(predicate: A => F[Boolean]) Does such a primitive exist, and am I overlooking it?
@TimoMeijer: yes, that's possible, but if you have more than one available in implicit scope, implicit resolution will no longer work of course
you have to manually import the "correct" one to make sure the correct functor is picked up. In scala 2 (not sure about 3), if it's not the rightmost parameter that's the functor hole, inference might not be able to infer correctly, be on the lookout for that.
if you have exactly 2 functor parameters, there is also bifunctor
Luis Miguel Mejía Suárez
@BalmungSan

@martijnhoekstra:matrix.org for what I can see you may do:

fa.flatTap { a =>
  predicate(a).flatMap(b => ev.raiseWhen(b)(t))
}

PS: Remember most folks are only on discord now.

Ups, you already asked there
Adam Rosien
@arosien
:point_up: January 17, 2022 11:04 AM @TimoMeijer it's not common or recommended to have multiple functor instances for a type. what people often do is use Bifunctor, to handle types with 2 type parameters, or if there are 2 type parameters you can implement a swap method which reverses the parameters and lets you map over the other side, then swap back.
Serhii Dashko
@sergeda
Hi. I'm looking for a way to change left part of the Either from concrete class to it's parent trait. Is it possible to do it without .leftMap[MyParentErrorTrait](identity))?
3 replies
Paweł Jurczenko
@pjurczenko
@sergeda you can use .leftWiden[MyParentErrorTrait] in this case
1 reply
Ciara O'Brien
@CiaraOBrien
has anyone worked out a particular use case for cats-effect's Supervisor?
looking at the code it doesn't even seem as though it does much other than having the whole batch get cancelled at once when the supervisor's fiber gets cancelled
though it seems to have aspirations at something else
though tbf I'm not familiar enough with the internals of this stuff to really make a statement on that
Luis Miguel Mejía Suárez
@BalmungSan
@CiaraOBrien this chat is mostly dead, try asking in the #general channel of the discord server: https://discord.gg/uTnfsCy4
nrktkt
@nrktkt:matrix.org
[m]

Is there a nice way to turn
A => B
A => C
A => D

Into

A => (B, C, D)

?

Luis Miguel Mejía Suárez
@BalmungSan
@nrktkt:matrix.org 99% sure you can just use tupled
nrktkt
@nrktkt:matrix.org
[m]
I went afk but I think the input is the fixed half of the generic for function instances
Luis Miguel Mejía Suárez
@BalmungSan
Yup, exactly for that is that I think it should work.
Yup, that does the trick.
ikempf
@ikempf

Hi, I've been using Show extensively as it's far safer than relying on toString.
But there are situations where I feel it's still not the right tool.

val id = ""
val url = show"http://service?id=$id"

If I were to change id from a String to a case class, this would not compile anymore (which is great).
But if I change id to an Option[String] this would still compile and give incorrect results.
This is of course intentional since there are Show instances for Option, List, Map etc. but this does make it feel like a debug tool.
Is there a known typeclass with similar but more "constrained" semantics ? (that would only provide instances for primitive types for example)

Luis Miguel Mejía Suárez
@BalmungSan

@ikempf

but this does make it feel like a debug tool.

Which is what it is; nothing more.

You are right, Show is not the right tool to interoperpolate URL parameters.
You may see if the http4s syntax provides something, otherwise you may create your own typeclass and interpolator.
Naftoli Gugenheim
@nafg
There's also lemonlabs scala-uri
ikempf
@ikempf

I should have specified that my question was not about URIs specifically but any interpolation that is either user-facing or might impact the application (so anything outside of debug logs).
This might include a file path show"tmp/$fileName or a message displayed to the user "You added $count items to the cart. I've been using Show for years for these cases but, as mentioned previously, it does not prevent all mistakes that might occur during refactoring (ex: String becomes a List[String]).

You may see if the http4s syntax provides something, otherwise you may create your own typeclass and interpolator.

I could create my own typeclass but was hoping for something more widespread. I mostly see interpolations using the s" or show" interpolators, both of which do not provide strong guarantees against type refactorings. But I guess the typeclass I'm looking for does not exist :(

Kiril Yurovnik
@KirilYurovnikRiski

Hi. Is it possible to define a Bifunctor with constraints on either of the 2 type parameters?
For instance, given a specific Handler[A, B], I'd like to define a Bifunctor[Handler] but only if some type class Foo is available for A.

implicit def handlerBifunctor: Bifunctor[Handler] = new Bifunctor[Handler] {
  override def bimap[A, B, C, D](fab: Handler[A, B])(f: A => C, g: B => D): Handler[C, D] = {
    /* This requires functionality provided by Foo[A] */
  }
}

Trying to alter the signature of bimap above:

  override def bimap[A: Foo, B, C, D]...

results in a Method 'bimap' overrides nothing error.

Luis Miguel Mejía Suárez
@BalmungSan
@KirilYurovnikRiski no, you can't, because as the error says your definition does not match the one from the interface.
amuradyan
@amuradyan
hey guys
I'm new to cats and I've decided to use the OptionT
when testing it though, I can't map into it since it says no instance of a Functor[Future] is found
I've imported /exclusively/ cats.implicits._, cats.instances.future._, and a few other things in a few different scopes but my scalatest wont confess to having an instance of future functor
Do you have any tips on what should be imported where?
Luis Miguel Mejía Suárez
@BalmungSan
@amuradyan you need an implicit Execution Context for the instances of Future
However, check this:typelevel/cats#4230
amuradyan
@amuradyan
Thanks, It was a dumb type error somewhere in between
dylanusdt
@dylanusdt:matrix.org
[m]
I'll help 10 individuals how to earn $20,000 in just 72 hours from the crypto/forex market. But you will pay me 10% commission when you receive your profit. if interested send me a direct message via Whatapp by asking me HOW for more details on how to get started
+1 (570) 801-0862
falconhash
@falconhash:matrix.org
[m]
Never depend on a single income to get financial freedom. I can teach you how you can earn from $5,000 to $6,000 weekly,without sending money to me or anyone, but you will pay me 10% commission when you receive your profit. if you are interested, ask me how via Whatsapp
👇👇👇
+1 (570) 801-0862
Mehmet
@mehmetcc_twitter

I need to log the failure type of EitherT and then transform this into an OptionT, something akin to this:

    someComputations()
      .orElse {
        case failure: Failure =>
          error(failure.message.getOrElse("failover_message"))
      }
      .toOption

However when compiled, I get this error:

missing parameter type for expanded function
[error] The argument types of an anonymous function must be fully known. (SLS 8.5)
[error] Expected type was: cats.data.EitherT[scala.concurrent.Future,?,?]
[error]       .orElse {
[error]               ^