It=E2=80=99s doing what you programmed it to do.

You=E2=80=99re d= oing a =E2=80=9Cprintln=E2=80=9D on the first arg (args.one), then a print on the second= arg (args.two.

So on your first 2 calls=E2=80=A6

f(one: =E2=80=9Cstring=E2=80=9D, two: false), prin= ts

=C2=A0=C2=A0=C2=A0=C2=A0 string (the line fieed in print= ln)

=C2=A0=C2=A0=C2=A0=C2=A0 false (no linefeed)=

then f(one: =E2= =80=9Cstring=E2=80=9D, two: true), prints

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0string (= linefeed)

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 true

So if you combine th= e outputs, it=E2=80=99s indeed

<= /p>

=C2=A0=C2=A0=C2=A0=C2=A0 string (the line fieed in println)=

=C2=A0=C2=A0=C2=A0=C2=A0 false (print, no linefeed) string (linefeed)=

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 true

So. w/o the explanations, =C2=A0l= ooks exactly what you have

=C2=A0=C2=A0=C2=A0 =C2=A0string<= o:p>

=C2=A0=C2=A0=C2=A0=C2=A0 false string

=C2=A0=C2=A0=C2=A0=C2=A0 true

=

F= rom: Rathinavelu <r= athinavelu@gmail.com>
Date: Saturday, April 25, 2020 at 9:23 PM
To: "use= rs@groovy.apache.org" <users@groovy.apache.org>, "users@groo= vy.apache.org" <users@groovy.apache.org>, David Karr <davidmic= haelkarr@gmail.com>
Subject: RE: Re: Strategy for optionally ex= cluding a named method parameter?

Both named and var= ag

def f(Object[] args){ println args.one

= print args.two }

f(one: "string",= two:false)

f(one:"string", two:tr= ue)

f(two:false)

f(two:true)

f(two: 1=3D=3D2)<= /p>

f(two: 1=3D=3D1)

f(two: 1= =3D=3D2)

[string]

[false][string]

[true][null]

[false][null]=

[true][null]

[false][null]

[true][null]

[false]

Please as a work around keep the boolean as= the last parameter. Since map is a subclass of  Object, = the function polymorphically accepts map object . But why Boolean be = the last to work? Sorry, Sir! I am into groovy only from last week! A long w= ay to go!

The reason for always =E2=80=98false=E2=80=99= in the middle perhaps  is =E2=80=9Cinvisible input=E2=80=9D. Last output has no [n= ull]

T.Rathinavelu

Sent from Mail for Windows 10

From: = MG
Sent: Sunday, April= 26, 2020 5:00 AM
To: use= rs@groovy.apache.org; David = Karr
Subject: Re: Strategy for optionally excluding a named me= thod parameter?

=

Hi David,

since, as w= as mentioned, named parameters are implemented as a map underneath in Groovy= , you should be able to remove the map entry of the parameter you do not wan= t to pass, though I did not try this myself...

Cheers,
mg

<= br>

On 25/04/2020 20:57, David Karr wr= ote:

On Sat, Apr 25, 2020 = at 2:00 AM Rathinavelu <rathinavel= u@gmail.com> wrote:

Named p= arameters are not available in Groovy, say, as in Python., though they say i= t is. Groovy has only mapped parameters. The earlier mail works for a single= =E2=80=98named=E2=80=99 parameter; if there are more parameters Groovy does not work as= =E2=80=98expected=E2=80=99; it treats them only as positional parameters.

Kindly mail me an use-case.

T.Rathinavelu

<= /div>

<= div>

The code sample looks something like this:=

functionName param1: value,

=

param2: v= alue,

&n= bsp;   param3: value,

=         param4: value,

...

= ;  param25: value

For instance, we need to make eith= er the previous call or the following:

&= nbsp; functionName param1: value,

param2: value,

param= 3: value,

&nb= sp;   ...

= ;     param25: value

Where the "= param4" key and value are not provided.  Presently, we have an &qu= ot;if" checking for a condition, followed by the "true" block= with the first version of the function call with 25 parameters, followed by= the "else" and the "false" block with the second versio= n, which has 24 parameters, all the same values as in the first block, excep= t for the one key and value not provided in the second version.

<= div>

Sent from Mail for Windows 10<= /p>

From: David Karr
Sent: Saturday, April 25, 2= 020 1:48 AM
To: users@groovy.apache.org
Subject: Strategy for optionall= y excluding a named method parameter?

Lately my only Groovy work is scripted pipelines in Je= nkins, version 2.89.4 .

I'm working with an api that is somewhat dumb in one respect. = The method we call takes ~25 parameters.  We send them as named parame= ters. One of the parameters is of boolean type.  What we've discovered = from testing is that if we send a value as either "true" or "= false", it acts as if we sent "true".  If we construct t= he call without that parameter entirely, it acts as if we sent "false&q= uot;. I tried making it send null, but that just causes it to fail at runtim= e.  We presently have an "if" for that one flag, with two cal= ls to the method, one taking 25 parameters, the other taking 24.  It is= really obnoxious.

Obviously, the proper fix is to change their api so that it works correc= tly.  The reality is, that's not going to happen any time soon in geolo= gical terms.

Is= there a concise groovy syntax we could use that would optionally include or= exclude a single parameter to the method?

<= p class=3DMsoNormal style=3D'mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'= >

=

--B_3670702226_1200923870--