Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Christopher Davenport
@ChristopherDavenport
Right, but what I really want is a rather simple syntactic change, and should be able to be automated somehow.
Fabio Labella
@SystemFw
heh, I'm not sure it's that simple, all things considered
Christopher Davenport
@ChristopherDavenport
Well noA => B => C => D to C => B => A => D should be doable.
Due to the implicit nature that’s the rearrangement, but it is baked into the language semantics that the transformation is not simple.
Fabio Labella
@SystemFw
there was a discussion a few days ago about supporting context bounds in higher-rank functions in scala 3, which was touching on a similar problem
I can see a few issues trying to implement mixing of implicits and not implicits lists. Not saying that is nonsensical or impossible, but it doesn't strike as particularly trivial, especially if you want to allow seamless explicit passing of implicit parameters as well
Fabio Labella
@SystemFw
@ChristopherDavenport if you want to indulge in evil
  def logMe[F[_]]: Magnet[F] = new Magnet[F]

  class Magnet[F[_]]
  object Magnet {
    implicit def conv[F[_]: Sync](m: Magnet[F]): LogMePartiallyApplied[F] =
      new LogMePartiallyApplied[F]

    class LogMePartiallyApplied[F[_]: Sync] {
      def apply(s: String, logAction: String => F[Unit] = { s =>
        Sync[F].delay(println(s))
      }) =
        logAction(s)
    }
  }

  def yolo = logMe[IO]("hello")
  // scala> yolo.unsafeRunSync
  // hello
tbh for a builder it's not that bad
changing names a bit
Christopher Davenport
@ChristopherDavenport
:100:
Luka Jacobowitz
@LukaJCB
How did you even come up with that :smile:
Fabio Labella
@SystemFw
I have this small library called eidos to encode IDs
mostly useless but I've learned a lot about bending scala to my will ;)
some of the stuff I have in a branch is truly crazy
like adding some sane error messages to that thing above
Christopher Davenport
@ChristopherDavenport
Sane error messaging, that seems unreasonable.
This is FP. 234sekjfasdf or it didn’t happen.
Fabio Labella
@SystemFw
with just that code if you do logMe("hello") you get "Magnet[F] does not get parameters"
let me see if I can remember how to fix that
(if it's fixable, lost track)
Christopher Davenport
@ChristopherDavenport
To be fair, logMe is definitely incorrect in the way scala does type identification in the first place.
Fabio Labella
@SystemFw
mm I think in the end I settled for just renaming apply to something else to get implicitNotFound-driven errors to work, can't quite remember anymore
I think the reason that makes it work in the correct scenario (it doesn't necessarily go through implicit search, but goes via the implicit conversion, thus avoiding the confusion between the input and the implicit parameter), it's also why implicitNotFound does not work (if it fails the implicit search you simply do not trigger the conversion)
Fabio Labella
@SystemFw
ah! I managed (just for the laughs though)
  def yolo = logMe[IO]("hello")
  // scala> yolo.unsafeRunSync
  // hello
  def well = logMe("hello")
Users/fabio/projects/playground/src/main/scala/Playground.scala:57: Specify `IO` there: `logMe[IO]("hello")`
[error]   def well = logMe("hello")
  def logMe[F[_]]: Magnet[F] = new Magnet[F]

  class Magnet[F[_]]
  trait LowPrio {
    @annotation.implicitNotFound("""Specify `IO` there: `logMe[IO]("hello")`""")
    trait Error
    class Catch[F[_]] {
      def apply(s: String, logAction: String => F[Unit] = ???)(implicit ev: Error) =
        ???
    }

    implicit def conv2[F[_]](m: Magnet[F]): Catch[F] =
      new Catch[F]
  }
  object Magnet extends LowPrio {
    implicit def conv[F[_]: Sync](m: Magnet[F]): LogMePartiallyApplied[F] =
      new LogMePartiallyApplied[F]

    class LogMePartiallyApplied[F[_]: Sync] {
      def apply(s: String, logAction: String => F[Unit] = { s =>
        Sync[F].delay(println(s))
      }) =
        logAction(s)
    }
  }
enjoy
Ross A. Baker
@rossabaker
So getting back to working around that error, I think the two questions are:
1) Do we want to be able to inspect the context on the builder?
2) What failure mode do we want if the default is bad and was not overridden?
Fabio Labella
@SystemFw
when you talk about 1), is the problem the fact that if you suspend the creation of SSLContext I can't see what's there without building one?
Ross A. Baker
@rossabaker
Yes.
Valentin Willscher
@valenterry
Is there a recommended way to unit test routes that returns streams of data?
I know that I can use the http4s web client for more integration-like tests, but I couldn't figure out how to test a routes (which is Kleisli) directly
The reason is that all the helper functions like HttpRoutes.of return org.http4s.package$#HttpRouteswhich is type HttpRoutes[F[_]] = Http[OptionT[F, ?], F] with Http being type Http[F[_], G[_]] = Kleisli[F, Request[G], Response[G]]
That means, the result will have Request[G] and Response[G] with the same effect - but my request is supposed to work with IO and the response should be a stream.
I can build that up myself, but I wondered if there is a better or already existing solution
Ross A. Baker
@rossabaker
orNotFound (on implicits) gets you to F[Response[F]]
map(_.body) gets you to F[Stream[F, Byte]]
Stream.eval gets you to Stream[F, Stream[F, Byte]]
And flatten gets you to Stream[F, Byte]
There's probably a shorter way but I just woke up and my brain is still booting.
Ross A. Baker
@rossabaker
I revisted that SSL issue. We can avoid that lazy hack in a binary-compatible way.
This as a default argument gets the job done: Try(SSLContext.getDefault()).toOption. The question is whether to log a warning that the default failed.
I'll open a PR and can discuss more there.
Ross A. Baker
@rossabaker
Nuts, my idea breaks semantics.
Christopher Davenport
@ChristopherDavenport
Yup, that’s not delayed.
Ross A. Baker
@rossabaker
I was going to add support for disabling SSL to get rid of the lazy hack.
Christopher Davenport
@ChristopherDavenport
I think that new solution is much nicer.,
Ross A. Baker
@rossabaker
It's a subtle change, so I moved that to 0.21. I think it would have been binary compatible.
Jakub Kozłowski
@kubukoz
Why was Uri.uri deprecated? The interpolator is nice, but it's quite hard to find the right import that doesn't end with an underscore
having two possible ways to write an URI from a string literal was actually cool