Re: [PROPOSAL]Support conditional return

2020-07-28 Thread Jochen Theodorou
On 27.07.20 18:13, MG wrote: [...] Continously reassigning to methodChosen  to itself once it has been set (or in your code: Once it has acquired a value that is Groovy-true) seems confusing & inelegant to me. I am actually using this style quite often, because of a lack of good alternatives. I

RE: [PROPOSAL]Support conditional return

2020-07-28 Thread Milles, Eric (TR Technology)
If switch expression or pattern match macro is insufficient, could a macro be written to cover this "conditional return"? // "it" could easily be replaced by "_" or "$" as mentioned previously as options def doSomething(int a) { returnIf(callB(), a > 6 && it > 10) returnIf(callC(), a > 5 &&

Re: [PROPOSAL]Support conditional return

2020-07-28 Thread MG
Like - would still be nice if we had a more Groovy syntax for Stream.of(...)/.stream() ... G-) On 28/07/2020 12:30, Jochen Theodorou wrote: well, with the streams API: return Stream.of(null,Character.TYPE,Integer.TYPE).   map {doChooseMethod(methodName, adjustArguments(arguments, it)}.   find

Re: [PROPOSAL]Support conditional return

2020-07-28 Thread MG
(The boolean case is a an aggregate, the second one only reassigns if no value is assigned, so I would use both. In contrast the example of yours I referred to wrote the value of foo every line without aggregating - this is what I found non-optimal... :-)  ) On 28/07/2020 12:30, Jochen Theodoro

Re: [PROPOSAL]Support conditional return

2020-07-28 Thread MG
I like that idea :-) (unless someone has a really convincing argument why not, 100% for sticking with "it" instead of "_"/"$") That would also allow for more flexibility with e.g. regards to the number of methods that are being evaluated, without getting into the problematic area of whether/

Re: RE: [PROPOSAL]Support conditional return

2020-07-28 Thread Daniel Sun
Hi Eric, I like your idea too ;-) We could use closure to express the condition at the tailing of method call: ``` def doSomething(int a) { returnIf(callB()) { a > 6 && it > 10 } returnIf(callC()) { a > 5 && it > 20 } returnIf(callD()) { a > 4 && it > 30 } } ``` Cheers, Daniel Sun On