Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
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]               ^
Mike Limansky
@limansky

Hi all. Could anybody please help with traversing Maps? For example I have function:

def foo(s: String): Either[String, Int] = if (s.forall(_.isDigit)) Right(s.toInt) else Left("Only digits allowed")

And I'd like to traverse Map[String, String] with it. As I understand I should use unorderedTraverse. But I've got following error:

@ Map("aaa" -> "123", "bbb" -> "321").unorderedTraverse(foo) 
cmd10.sc:1: could not find implicit value for parameter ev$1: cats.CommutativeApplicative[[+B]Either[String,B]]
val res10 = Map("aaa" -> "123", "bbb" -> "321").unorderedTraverse(foo)

What have I missed?

1 reply
alexchole
@alexchole:matrix.org
[m]
"I'll help 10individuals how to earn $30,000 in 72 hours from the crypto market. But you will pay me 10% commission when you receive your profit. if interested send me a direct message on Telegram by asking me (HOW) for more details on how to get started
https://t.me/+lD4Ec_gRjCljYjNk
rom1dep
@rom1dep:kde.org
[m]
hey there, I have a cats-effects (3.3.14 ; scala 3.2.0) question, I have an IO which I call with handleErrorWith:
blah(arg).handleErrorWith(_ => IO.unit)
any idea why I'm getting this error?
Main.scala:32:7: Found:    cats.effect.IO[Matchable]
Required: cats.effect.IO[Unit] [32:7]
rom1dep
@rom1dep:kde.org
[m]
oh, got it, I'm dumb :)
qurt
@qurt:matrix.org
[m]

Hi folks, I have a cats / cats-mtl related question, gitter for the latter doesn't seem very active so figured I'd ask here
I am playing around with mtl typeclasses and have the following:


 #!/usr/bin/env amm

 import $ivy.`org.typelevel::cats-core:2.8.0`
 import $ivy.`org.typelevel::cats-effect:3.3.14`
 import $ivy.`org.typelevel::cats-mtl:1.3.0`

 import cats._
 import cats.data._
 import cats.effect._
 import cats.implicits._
 import cats.mtl._


 case class Error(msg: String)

 type ErrorChannel[F[_]] = Raise[F, Error]

 inline def errChannel[F[_] : ErrorChannel] = summon

 def justThrow[F[_] : ErrorChannel]: F[Unit] =
   errChannel raise Error("Error!")


 def main[F[_] : Monad : ErrorChannel] =
   for
     r <- justThrow[F]
   yield
     r


 import cats.effect.unsafe.implicits.global
 main[EitherT[IO, Error, ?]].unsafeRunSync()

I get the following error
-- Error: /mnt/c/DEV/stuff/bs/mtl2.scala:34:40 --------------------------------- 34 |val res_13 = main[EitherT[IO, Error, ?]].unsafeRunSync() | ^ |No given instance of type cats.Monad[cats.data.EitherT[cats.effect.IO, ammonite.$file.mtl2.Error, ?]] was found for an implicit parameter of method main in object mtl2 Compilation Failed

I am running Ammonite Repl 2.5.4-33-0af04a5b (Scala 3.2.0 Java 11.0.16)
Am I mistaken in thinking EitherT[IO, Error, ?] has a Monad instance?
If I relax the constraint in main's F to Applicative and get rid of the for-comp I get a similar error

Maybe the instance is not visible because my imports are incorrect? I tried different combinations of imports to no avail so far. Any help much appreciated! 🙂

Naftoli Gugenheim
@nafg
@qurt:matrix.org try discord
cherrie11
@cherrie11:matrix.org
[m]

💨Don't miss your chance to be rich

✌️👍🙏DiscJockey is my name and I'm an admin with my own store link and group link https://t.me/+_kTifpKvc-kwNDJk

This is my group link, you can check and prove my legal work there.

🙏UPDATE My Services: Sell PayPal account verified – PayPal transfer Sell Bank Transfer – Bank Login Sell Clone card - Secure shipping tunnel cc Fullz sell and random Information – 99% valid cards Sell Dumps with pin track 1 and 2 101 201 Sell Western Union money transfer services Sell Gift Cards Itune – Amazon – Ebay Clone/Credit Cards Sell Booking airfare services – worldwide Sell e-carding services *SMTP - Pass Mail - PHP - Sell RDP !! Follow the Group Stage and contact me if you want to earn money! Let's make more bread! Obey the rules ! Whether you order it or buy it, get it instantly ✌️ Affiliate member required for a long-term business 🙏100%. 100% High Quality Good and Quality Castings+Pins 90% Approval

TRANSFER SERVICE

BTC/USDT/CASHAPP

TN PRAYER PAYMENT

PRAYER TO ARIZONA

What MASS UI DUA has

EDD RELOAD

ALL GOVERNMENT PRAYER PAYMENTS

METHOD IS AVAILABLE!!

FULLZ

PAYPAL

CASH APPLICATION

CASTINGS+PINS

FULLZ + CASTINGS

PAYPAL Transfer

CashaPP transfer

BANK LOG and bank deposits

CASTING + P!N

PRODUCT:%S

CVV+SSN/D

WU TRANSFER ♛

SCAN ALL APPLES ♛

Good sale QUALITY THINGS with a good product! With a large number of customers worldwide and also a Valid Reseller 🇺🇸

BESTBUY TAP & SHARE WORKING BOXES

VERIZON TAP & SHARE

WALMART - TAP & Pay Bin's

Amazon prime Tap and pay

••Cold random prices Random Boxes ••

COUNTRIES ! Verizon - AMAZON DUMPS with pin

AMAZON PART1-2

Verizon- Track2- 1 Pin

Walmart - Track1-2 Pin

Postcode + PINs

FULLZ + Ssn - details

FULLZ - ​​Dob + Pins

CV - Postal Code + ATM

Those who are ready and willing to abide by the rules should message or contact me immediately! Telegram ✅https://t.me/DiscJockie