by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Oleg Pyzhcov
@oleg-py
@maphi your example isn't very specific (and for ... yield is non-Unit itself). You can try disabling optimizations (-P:bm4:no-map-id:n and/or -P:bm4:no-tupling:n)
Philipp Martini
@maphi
@oleg-py thx that worked!
the line causing the error was the (a,b) = foo
Yuriy Badalyantc
@LMnet

Hi everybody! I had a problem with the cats.effect.Resource with the next code:

for {
  mongoClient <- Resource.make(acquire)(release)
  bookletsCollection <- Resource.liftF(getCollection(mongoClient))
  storage <- Resource.pure(createStorage(bookletsCollection))
} yield storage

And the error is:

[error] /.../MongoDbBookletsStorage.scala:45:31: value map is not a member of cats.effect.Resource[F,ru.dgis.market.booklets.storage.BookletsStorage[F]]
[error]       storage <- Resource.pure(createStorage(bookletsCollection))
[error]

I added better-monadic-for in my project to solve this issue. I checked in the sbt that compiler plugin was added. But I'm still facing the same issue. What am I doing wrong?

Manual rewriting solves the problem:
Resource.make(acquire)(release).flatMap { mongoClient =>
  Resource.liftF(getCollection(mongoClient)).flatMap { bookletsCollection =>
    Resource.pure(createStorage(bookletsCollection))
  }
}
But what better-monadic-for didn't do that for me?
Christopher Davenport
@ChristopherDavenport
You need import cats.implicits._ to have map on resource.
It is slated to be fixed in the next release of cats effect.
Yuriy Badalyantc
@LMnet
@ChristopherDavenport with this import a have another error:
[error] /.../MongoDbBookletsStorage.scala:42:31: diverging implicit expansion for type cats.kernel.Order[A]
[error] starting with method catsKernelStdOrderForVector in trait VectorInstances
[error]       storage <- Resource.pure(createStorage(bookletsCollection))
[error]
Oleg Pyzhcov
@oleg-py
@LMnet just use yield createStorage(...) or write pure with all types
Yuriy Badalyantc
@LMnet
@oleg-py tried yield createStorage:
[error] /.../MongoDbBookletsStorage.scala:44:43: value map is not a member of cats.effect.Resource[F,org.mongodb.scala.MongoCollection[org.mongodb.scala.bson.collection.immutable.Document]]
[error]       bookletsCollection <- Resource.liftF(getCollection(mongoClient))
[error]
Oleg Pyzhcov
@oleg-py
With import cats.implicits._
Yuriy Badalyantc
@LMnet
With imported cats.implicits._:
[error] /.../MongoDbBookletsStorage.scala:46:26: polymorphic expression cannot be instantiated to expected type;
[error]  found   : [F(in method pure)[_]]cats.effect.Resource[F(in method pure),ru.dgis.market.booklets.storage.BookletsStorage[F(in method apply)]]
[error]  required: ru.dgis.market.booklets.storage.BookletsStorage[F(in method apply)]
[error]     } yield Resource.pure(createStorage(bookletsCollection))
[error]
Oleg Pyzhcov
@oleg-py
With import cats.implicits._ and without Resource.pure
Yuriy Badalyantc
@LMnet
Now it works! Thanks
Oleg Pyzhcov
@oleg-py
Better-monadic-for doesn't remove the need for having a map, btw:
oleg-py/better-monadic-for#15
it can just sometimes optimize the call away, but it needs to typecheck first
Yuriy Badalyantc
@LMnet
It looks like I misunderstood the docs. I thought that bm4 could completely remove map.
Thread in the issue is helpful
Oleg Pyzhcov
@oleg-py
It would remove map, but only if it can prove it's safe to do. And to prove that, it needs to be done after typer
Jakub Kozłowski
@kubukoz
image.png
latest nightlies of IDEA seem to work with implicit0 :P
thanks to the work of @sugakandrey
Christopher Davenport
@ChristopherDavenport
:100:
elyphas
@elyphas
Hi, someone could help me? please, I add the plugin, but I do not know how to activate the plugin.
elyphas
@elyphas
I was wrong I thought that it was a plugin but is compilerPlugin, sorry
It compiled without errors
Philippe Derome
@phderome
Is it just me? I accidentally misused better-monadic-for for a few minutes and then all kinds of wartremover problems started to kick in. If this is a very common question, maybe an explanation in the README would be nice?
Philippe Derome
@phderome
@phderome it seems that I require this in my build.sbt
wartremoverErrors ++= Warts.allBut(Wart.Product, Wart.Serializable)
Oleg Pyzhcov
@oleg-py
@phderome that is not impossible, but it's the first time I hear anything re wartremover specifically. If you can minimize the code causing the issue, that would help me to investigate.
Philippe Derome
@phderome
Thanks! I somehow suspect I am misusing sbt first and foremost, but if I do come down to the bottom of it, I'll see if I can minimize and come back here, no promise though.
Ross A. Baker
@rossabaker
I just tried to submit a PR for 2.13.0-RC1 support, and was surprised by all the test dependencies. I can imagine some of those libraries wanting to depend on better-monadic-for and causing a circular dependency.
Would there be interest in a PR that made its own test monad without withFilter and with its own FlatMap typeclass, since this plugin is increasingly used?
Ross A. Baker
@rossabaker
I don't know as obvious an alternative to pcplod.
Oleg Pyzhcov
@oleg-py

@rossabaker thanks for the effort in upgrading!

I think the better way would be to split test dependencies for pre-2.13 and 2.13. I find it important to have tests with at least Scalaz and Cats as the plugin is primarily oriented towards using those even if not yet for 2.13. Same for pcplod, fine to only have it where we can.

IIRC, compiler plugins don't become transitive deps, so bm4 depending on libraries using bm4 should be totally fine too.

Ross A. Baker
@rossabaker
Yeah, that's a good point on the circular dependency.
I'm more concerned about the mapped unit. Did those tests successfully run on 2.13 or is that a regression?
Oleg Pyzhcov
@oleg-py
Tests were never ran on 2.13 :D On 2.12 everything is fine (lots of warnings, but no errors)
Oleg Pyzhcov
@oleg-py
It's also totally possible that some compiler internals have changed and it needs to be redone. You can just comment the test out and leave it for me to take a look when I get time (hopefully this weekend)
Ross A. Baker
@rossabaker
It's just the one test that fails, but yeah, there's one regression on 2.13. You can see it by running ++2.13.0-RC1 test on my PR.
Ross A. Baker
@rossabaker
Okay, I split it into a multi-module build so dependencies can come and go. Core functionality is still tested with a custom, withFilter-less monad. Cats syntax is tested in its own module where possible. pcplod is tested in its own module where possible. The 2.13.0-RC1 test still fails.
Ross A. Baker
@rossabaker
Alright, I think I fixed it.
Oleg Pyzhcov
@oleg-py
@rossabaker it's live on central now. Thanks a lot 🎉
Ross A. Baker
@rossabaker
:tada: thanks for the release!
Brandon Elam Barker
@bbarker
Hi - I recently updated to sbt 1.2.8 so I could use this plugin (great to update anyway from 0.13.7!) Anyway, I noticed it didn't take care of my withfilter issue:

For the code snippet

    for {
      jobId: JobId <- (
        if (jobPath.toIO.exists()) IO.succeed(job.id)  : IO[String, JobId]
        else jobContextService.createContext(job) : IO[String, JobId]
      )

I would get (and still get) this error, after having added addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.0") to my plugins.sbt:

Executors.scala:92:9: value withFilter is not a member of scalaz.zio.IO[String,org.xsede.jobrunner.model.ModelApi.JobId]
[error]         if (jobPath.toIO.exists()) IO.succeed(job.id)  : IO[String, JobId]
[error]         ^

So I appended the compiler options explicitly to see if that made a difference in my build.sbt:

val commonSettings = Seq(
  version := "1.0-SNAPSHOT",
  scalaVersion := scalaVersionSelect,
  scalacOptions ++= Seq(
    "-encoding", "UTF-8",
    "-feature",
    "-unchecked",
    "-deprecation:false",
    "-Xfatal-warnings",
    //"-Xlint",
    "-Xlint:-unused,_",
    // "-Ywarn-unused:imports", // Disabling during normal dev - too annoying!
    "-Yno-adapted-args",
    "-Ywarn-numeric-widen",
    "-Ywarn-value-discard",
    // "-Xplugin-require:macroparadise", // For scalameta version only?
    "-Xfuture",
    "-P:bm4:no-filtering:y", // Desugaring without withFilter (for)
    "-P:bm4:no-map-id:y", // Elimination of identity map (for)
    "-P:bm4:no-tupling:y", // Elimination of tuples in bindings (for)
    "-P:bm4:implicit-patterns:y" // Implicit definining patterns (for)
  ),

But that results in:

[error] bad option: -P:bm4:no-filtering:y
[error] bad option: -P:bm4:no-map-id:y
[error] bad option: -P:bm4:no-tupling:y
[error] bad option: -P:bm4:implicit-patterns:y
[error] bad option: -P:bm4:no-filtering:y
[error] bad option: -P:bm4:no-map-id:y
[error] bad option: -P:bm4:no-tupling:y
[error] bad option: -P:bm4:implicit-patterns:y
[error] bad option: -P:bm4:no-filtering:y
[error] bad option: -P:bm4:no-map-id:y
[error] bad option: -P:bm4:no-tupling:y
[error] bad option: -P:bm4:implicit-patterns:y
Brandon Elam Barker
@bbarker
nevermind, I realized that addCompilerPlugin(...) should be in my settings() in build.sbt, not plugins.sbt
David Gregory
@DavidGregory084
Thanks for starting that discussion @oleg-py :)
You wrote things up better than I could have