Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 02:42
    sjrd commented #1251
  • 01:42
    SethTisue commented #1431
  • 01:39
    SethTisue commented #1431
  • 01:22
    retronym edited #778
  • 01:20
    retronym edited #778
  • 01:12
    retronym opened #778
  • 01:01
    SethTisue edited #1432
  • 00:15
    SethTisue synchronize #1430
  • Jun 16 23:45
    scala-jenkins milestoned #9671
  • Jun 16 23:45
    retronym opened #9671
  • Jun 16 23:24
    SethTisue edited #1432
  • Jun 16 23:23
    SethTisue edited #1432
  • Jun 16 23:20
    SethTisue edited #1432
  • Jun 16 23:20
    SethTisue edited #1432
  • Jun 16 22:23
    SethTisue opened #1251
  • Jun 16 21:28
    SethTisue synchronize #1430
  • Jun 16 21:13

    SethTisue on 2.13.x

    Fix exception message from prod… Consolidate productElementName … Merge pull request #9645 from s… (compare)

  • Jun 16 21:13
    SethTisue closed #9645
  • Jun 16 21:12
    SethTisue labeled #9645
  • Jun 16 21:05
    smarter commented #769
Dominic Egger
@GrafBlutwurst
yeah that's what I'm doing anyway I don't want to expose the caching to external user except size
ah I see
<3 looks exactly like what I needed thanks!
Fabio Labella
@SystemFw
let me know if you're having problems encoding the logic you need there, but generally fs2.Ref + fs2.Promise (now cats.effect.Ref and cats.effect.Deferred) are your friends
moritz bust
@busti
Is there a way to automatically create a companion object for a class?
ndv87
@ndv87
@Busti in IDEA u can Alt+Insert -> Comp obj
moritz bust
@busti
That is a nice idea, but I am thinking more about a code thing here...
What I am trying to do is to implicitly create a companion object for every child of a class. Since it always has the same members, there is no need to re-write it every time that class is extended.
But I guess that could only be solved by codegen, which might not be that good of an idea.
Dominic Egger
@GrafBlutwurst
@SystemFw this does this seem sensible?
I'll only have to do a fixed size alternative to Map and evict LRU style when adding
maybe just use Chris' scalacache
Fabio Labella
@SystemFw
@GrafBlutwurst there's a problem with that
you are creating new Ref and HttpClient every time
with the Client, it's just wasteful
with the Ref, it won't work because you aren't sharing the state
Dominic Egger
@GrafBlutwurst
lazyness?
Fabio Labella
@SystemFw
nope, purity
if you mention cache, you create a new cache
Dominic Egger
@GrafBlutwurst
oh right. substitution ... derp
Fabio Labella
@SystemFw
if you want to share the state, you need to pass it as an argument and flatMap everytime
this is a feature because it means that the region of state sharing is the same as your call graph
but you need to get used to it
in caching terms, caches always reduce to having type IO[IO[A]], and not IO[A]
Dominic Egger
@GrafBlutwurst
so i necessarily need to expose my state outside?
Fabio Labella
@SystemFw

in this case if you have

trait Cache[F[_], A] {
   def get: F[A]
}

then the constructor needs to be

object Cache {
  def create: F[Cache[F, A]] = ....
no, you don't have to expose the state, but you will have F[Cache[F,
and for that the same argument applies, you need to pass the cache wherever it's needed, and then create it and flatMap it once at the end of the region of sharing you want to create, e.g. main if your whole app needs it
you can always unsafeRunSync it if you want a truly global one but I'd discourage that
I'd rather be in full control of who shares what state
Vasco Dias
@vascorsd
Hi, is there other ways to define the jvm flags required for scala to compile when using sbt (specifically the Xss)? I' using the $JVM_OPTS environment var. I see it could be maybe also on $SBT_OPTS or any of the opts files that sbt also runs. I'm wondering because I have a colleague saying it should go inside the build.sbt file directly and stay defined there... looking for a good reason and/or argument why it shouldn't.
Fabio Labella
@SystemFw
The same argument goes for the HttpClient (and for all stateful things actually)
Dominic Egger
@GrafBlutwurst
so my ioSchemaRegistry not only needs a URL but also a cache passed?
Fabio Labella
@SystemFw
nope
the code that uses ioSchemaRegistry needs to be passed ioSchemaRegistry
because ioSchemaRegistry will return IO[SchemaRegistry[IO]]
Dominic Egger
@GrafBlutwurst
I need a moment to wrap my head around this
Fabio Labella
@SystemFw
and so the same argument applies, if you flatMap twice you get two different caches, and you create two different regions of state sharing
well, there is a blog post with a link to like 4 of my explanations
so if you want to read more I can give you a ton of links
anyway for the HttpClient, the state is the connection pool
Dominic Egger
@GrafBlutwurst
yes please
Fabio Labella
@SystemFw
yeah, just a sec
btw this is one of the greatest features of pure FP, I'm giving a talk on it at Scala Italy in September
Dominic Egger
@GrafBlutwurst
this seems pretty basic and intuitive that this won't work. don't get why I haven't seen it
heh, everyone understands it perfectly once explained. Also everyone gets confused the first time they see it
the last paragraph of https://underscore.io/blog/posts/2018/03/20/fs2.html is also interesting, the author had made the same mistake originally (in the context of sharing a Topic)
Dominic Egger
@GrafBlutwurst
def ioSchemaRegistry(schemaRegistryURL: String Refined Url):IO[SchemaRegistryAlgebra[IO]] =
    Monad[IO].product(Http1Client[IO](), Ref.of[IO, Map[Int,String]](Map.empty[Int,String])).map(
      tpl => {
        val client = tpl._1
        val cache = tpl._2

        new SchemaRegistryAlgebra[IO] {
          private[this] def appendToUrlIO(url:String Refined Url, suffix:String):IO[String Refined Url] = appendToUrl[Throwable, IO](es => new RuntimeException(es))(url, suffix)

          override def getSchemaStringForID(id: Int): IO[String] = for {
            map <- cache.get
            res <- map.get(id).fold(
              for {
                url <- appendToUrlIO(schemaRegistryURL, s"schemas/ids/$id")
                resultString <- client.expect[String](url.value)
                out <- cache.update(currentCache => currentCache + (id -> resultString) )
              } yield resultString
            )(IO.pure)
          } yield res
        }
      }
    )
I think I'm getting closer
Fabio Labella
@SystemFw
yep, you're getting closer