-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 new lengthIs
method (more usable than lengthCompare
)
#6758
Conversation
754e052
to
5f346e3
Compare
Since the point of |
YMMV but I’m not a big fan of introducing intermediate classes for the sole purpose of providing a DSL that reads nicely (a la ScalaTest). I’d rather go with |
@julienrf - Me either, normally. But are you more of a fan of underscores in method names and hybrid alphanumeric-symbolic method names? Especially after all the effort of providing non-symbolic equivalents for the purely symbolic and trivial to understand methods in collections? That would suggest the choices are either an intermediate class (hopefully zero-overhead) or |
@Ichoran I agree that it could use some bikeshedding. Perhaps |
The results are:
The current way of doing it is not even consistently cheaper, and for the smaller values, the new way was only 1ns slower in one of the benchmarks. So, if there is a performance hit (which is not clear to me), it's an extremely small one, and probably not noticeable. TL;DR the cost seems to be negligible to non-existent. |
👍 👍 from me, but different people may prefer different colors of shed. I think it is a very usable and intuitive API this way--you get only-as-much-as-needed evaluation, yet you can use the slightly-higher-level concepts you're already familiar with, and with only one thing to learn. With |
I also tweaked |
Is it worth |
12f4cde
to
a997e69
Compare
I like this a lot, and definitely prefer it over adding multiple methods with underscores in their names. |
I seem to be approaching this from a different angle than @Ichoran. This looks like a daunting amount of complexity for very little gain. The resulting syntax is very nice but getting to that syntax is anything but nice. The necessary machinery shows up in scaladoc and can leak out in error messages. IMHO the goal of any syntactical sugar for |
I don't think that's "quite natural" to everyone, and even if it is natural, it's one extra mental transformation instead of zero. I guess it could be made more natural to everyone if the docs say exactly what you said (that is, |
4f2722c
to
3cf8f79
Compare
squashed |
Are we moving forward with this? |
Elaborating on this question, there are two possible sets of methods to inline: { |
It seems that your benchmarks show no overhead for |
For trivially small collections (only a couple of elements), it seems like there's maybe a cost of around a third of a nanosecond (ish), which on my processor, is about 1 cycle. For non-trivially small collections (where using |
Add `SeqOps.lengthIs`, which returns a value class containing symbolic comparison operators. Tweak `SeqOps.lengthCompare` to check `knownSize`.
519d0f6
to
41d5286
Compare
squashed with |
Thanks, @NthPortal! |
lengthIs
method (more usable than lengthCompare
)
yw! 😊 |
Fixes scala/collection-strawman#338