-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Function same as with
, but returns the incoming object
#174
Conversation
without saying we should do this, there is at least one part that needs improvement. Your tests do not check the returned value at all. Since that is what is one deciding factor to have this method at all, I would say testing the returned value is absolutely required |
yes, there currently is only one "happy path" test and the rest is the |
Just wanted to note that GROOVY-3976 is an open JIRA related to this. FWIW, I kind of agree with the reporter and would be surprised if many rely on the current behavior of |
Well I don't do ruby, so I have no opinion on the naming; if ruby is the source to look for names, I happily change it to |
Nice change, wanted to do this myself also. Also, please check for Btw, wouldn't it be simpler to implement it as def doto(self, closure) { self?.with(closure); self } (with extension methods, of course) |
@christoph-frick Thanks for putting this together, it's been an outstanding request for 6+ years. There seems to be enough support for this feature, and only the naming discussion is holding it up. If you don't mind changing the method name to tap, then it seems like this could be merged. |
IMHO |
@dovchinnikov |
@christoph-frick It doesn't mean anything in Groovy :) Groovy already has |
"apply" makes a lot of sense to me. Now that I know that Kotlin has the exact same feature named apply, it seems to me to be the obvious choice. |
Hi Christoph, I think this is useful and we should go ahead - we mostly seem to be stalled on naming. Any chance you can rename to 'apply' to match Kotlin's naming scheme and add the tests that Jochen suggested and rebase? Once done I'll send an email to the users mailing list to get any final thoughts on naming alternatives (a final rename is easy if needed) and I can help get this through into 2.5. We hope to release a beta shortly. If you also wanted to add in some doco, feel free otherwise I'll do that. [search for 'Using with() for repeated operations on the same bean' within style-guide.adoc to find the right place and no I don't know why it is only there but that will do]. |
I am really sorry, for causing so much turmoil. That patch was not considered For me, Groovy naming is odd, since I am no Ruby developer in the first place, Since to me Kotlin has its influence from Groovy, "back-porting" a Kotlin name |
Hi Christoph, I was planning on getting more feedback on the name in the mailing list. I was just suggesting Would any of these names work for you: P.S. inject and collect come from Smalltalk not Ruby. P.P.S. and it's not the case that your PR was ever considered 'not worthy', it's just that naming is hard and we prefer to delay and get right rather than rush and make further naming even harder down the track. |
@paulk-asert No hard feelings here. "not worthy" as in: it seems not enough a common problem. I have now rebased the patch against upstream, renamed to function to As for the name, feel free to settle on one with the groovy elders (but not |
Thanks! That looks good. I'll send an email to the users list and ask for feedback on the name. |
doto
: same as with
, but returns the incoming objectwith
, but returns the incoming object
+1 for |
Hey Christoph, the general consensus seems to be tap plus with(true) as an alternative option (basically a variant with an extra "boolean returning" parameter). Plus we need a little bit of asciidoc doco. Are you happy to do either of these or are you happy for me to take the PR as is and make the necessary tweaks? |
@paulk-asert I have added some documentation at the spot you suggested earlier. Feel free to take over from here - or let me know, if something is missing I can do. |
I'm for |
@christoph-frick thanks, I'll take it from here - will let you know if there are any problems @graemerocher yes, |
Proposed PR and some minor tweaks applied. Thanks everyone for the contribution, discussion and patience. |
My usecase for
with
is >80% to (ab)use it as some sort of builder. Since I end up putting close to always(return) it
at the end of my closure:doto
tap
is a slight variation ofwith
, that just returns the incoming object.doto
is a loanword from clojure,tap
is a loanword from Ruby (see comments below) where it does the same and I could not find a naming scheme for groovy, that would not involve renamingwith
(which is impossible).