-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add buildable for java.util.HashMap #1023
Conversation
59c51a0
to
5bfe51a
Compare
@RustedBones thank you for the contribution! May I clarify one question please? implicit def wrapArrayList[T](xs: ArrayList[T]): Traversable[T] = xs.asScala
implicit def wrapHashMap[K, V](xs: HashMap[K, V]): Traversable[(K, V)] = xs.asScala Does not seem to me that those are required for the " |
Those implicit are there to fulfill the evidence Without them, val arrayListGen: Gen[java.util.ArrayList[String]] = Gen.containerOf(Gen.alphaStr) fails with
And val hashMapGen: Gen[java.util.HashMap[String, Long]] = Gen.buildableOf {
for (str <- Gen.alphaStr; lng <- Gen.long) yield (str, lng)
} fails with
|
Oh, I see now, thank you for the clarification! To be honest, that constraint looks quite odd to me. It does not seem to be used in the code for the sake of generation, but as just a constraint only: implicit def arrayListAsIterable[A](al: util.ArrayList[A]): Iterable[A] = null
forAll { (al: util.ArrayList[Int]) =>
println(al)
true
} I.e. the conversion function is not called from the generation code at all. Looks like that constraint was first introduced by @rickynils in this commit:
But I am not sure what could it mean exactly and whether collections like ArrayList are supposed to be supported in this way. |
It looks to me this constraint has been added so that we can also create a An implicit IMHO the unused evidence on |
Yes, I see what are you talking about. Perhaps, it was the idea behind that decision indeed. However, I personally don't feel it should be done that way: On the other hand, it is hard to say for sure. It was 2013 after all – the reign of Scala 2.9 and a time of numerous experiments with implicits and controversial decisions sometimes. Back to the PR...
It still works in Scala 2.13 and even 3.x but deprecated and most likely will be removed somewhen. So I am on a fence here - do we really want to get a quick solution by re-introducing the deprecated behavior back to the library? Or may it be worth of thinking out a better approach from a long-term perspective, wdyt? |
I think this statement is not correct
In order to remove a chunk from the container Concerning the direction of the library, even if TBH I mainly opened this PR because of the documentation here
In practice, I would be fine to remove |
Actually I mean that
In fact, at the moment when So maybe as a trade off solution, and instead of baking our own ad-hoc implicit conversions into
to allow users simply add this import to their code
and therefore help them to avoid the deprecation warnings in there. Or ultimately we can simply add a note about it to the docs and let users take care of it theirselves. |
Sounds like a good solution. Will update the PR and the doc accordingly. |
282b6f6
to
94532f3
Compare
Sorry for the delay @satorg I lost track of this PR. |
@RustedBones , I apologize that reviewing your PR is taking that much time. Honestly, I lost tracking of it for a while, sorry for that. It looks great to me overall, however I noticed a couple of concerning places, could you clarify on them please? Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
As
java.util.ArrayList
is supported incontainerOf
, introduce builder to generatejava.util.HashMap
from tuple generator.The doc states
java.util.ArrayList
is supported by default, but the implicit evidenceevt: C[T] => Traversable[T]
is missing. Adding it inBuildableVersionSpecific
.Add new instances in
BuildableSpecification
to verify compile ability.