From users-return-4316-apmail-groovy-users-archive=groovy.apache.org@groovy.apache.org Sun Apr 26 01:23:53 2020 Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 69E9B19F83 for ; Sun, 26 Apr 2020 01:23:53 +0000 (UTC) Received: (qmail 95583 invoked by uid 500); 26 Apr 2020 01:23:52 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 95551 invoked by uid 500); 26 Apr 2020 01:23:52 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 95539 invoked by uid 99); 26 Apr 2020 01:23:52 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Apr 2020 01:23:52 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id CABF1C1DDE for ; Sun, 26 Apr 2020 01:23:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.3 X-Spam-Level: * X-Spam-Status: No, score=1.3 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=0.2, MIME_HTML_ONLY=0.3, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-he-de.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id Y-iJaPF-QzrJ for ; Sun, 26 Apr 2020 01:23:47 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2607:f8b0:4864:20::42a; helo=mail-pf1-x42a.google.com; envelope-from=rathinavelu@gmail.com; receiver= Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by mx1-he-de.apache.org (ASF Mail Server at mx1-he-de.apache.org) with ESMTPS id 5DB787DD96 for ; Sun, 26 Apr 2020 01:23:46 +0000 (UTC) Received: by mail-pf1-x42a.google.com with SMTP id r14so6930089pfg.2 for ; Sat, 25 Apr 2020 18:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:mime-version:date:from:subject:thread-topic:to :content-transfer-encoding; bh=m7GblpQQHkaGU8bocTztXO35efXRz23gVev/W0Hv8eM=; b=GIEWF5BsVXWLIQZsMQwz59C3poEhIkFkATbZpfIofXrj9hvJ9CzkCHMOAGi3HaaP5j VtKejQyz1HUB2Ov8EJLVqhS90QS71wXeIYuUcxphxHKDNOmW+09vjAUiI+WbrBzzPW7U 8Y/ylHnz0Qh/RJvsjLJp0rK/8okALtWmd9QJ603+/Y0Pes1voxSpnpQS8dfoKGY8XgQS lzQ23o3VATmHic8QVIFwGJ2LLKPEOFceSEt+QZGTD4xMQabQ8hdTuLyCsbW47sOK72HY ljJGN9TwRRSnNhD6rnRDr77/PmMf3IKJPupfgfyH1XwzX341nv3wZpqeNDFDsahBQ3L7 Ya8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:mime-version:date:from:subject :thread-topic:to:content-transfer-encoding; bh=m7GblpQQHkaGU8bocTztXO35efXRz23gVev/W0Hv8eM=; b=qjClaER6knZzOKX7FJKK8h20ULyOG9LCXv/Bgyh9EDXXs7KOY0gOQIZcrYp9ppM0Id fUaLOZ3K1N5IBABgBo80JMF1gsKpT+HjEQvomQV7fzuPbjbThKcIfXDQyFSwTkXNkbw4 CdOAc2LgTTB8fm84/QGc5/NzsGwQL1eU3l8ZbLoEeu9ciNyp+XNDjKrasHxSiWQfdkmi MxZ9JU4s4fmgKXW9vII5eF4iP0kll60QxK8b/5YuqcN82XE4rphoL5SfkRPrQSzpUNco Flms56re5YHtmZDwVS0vtJw46eVyTEviy/jHdyB6KGfWGmHA768+Q/PxshQISvT6L/QX Rzew== X-Gm-Message-State: AGi0PuYtR0U/qUZ9WqMFu0RYGq/n+AH1EUU19vDJlUcj4u/6cfeR71ru zaJ0o8gKf8Ruja67peSn/xHK2xWq8bA= X-Google-Smtp-Source: APiQypICWGOPW8MWTifZ992PM2cB6Jau+ZtEGV7nV0addxusL4yxoB2PEAEfuH9if4ijnEHSeUVbCg== X-Received: by 2002:a63:1a1e:: with SMTP id a30mr15969454pga.368.1587864218330; Sat, 25 Apr 2020 18:23:38 -0700 (PDT) Received: from smtp.gmail.com ([2405:201:e808:1fea:8140:6e9:6392:c74a]) by smtp.gmail.com with ESMTPSA id d184sm8720330pfc.130.2020.04.25.18.23.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Apr 2020 18:23:37 -0700 (PDT) Message-ID: <5ea4e299.1c69fb81.ccc17.0540@mx.google.com> MIME-Version: 1.0 Date: Sun, 26 Apr 2020 06:53:32 +0530 From: Rathinavelu Subject: RE: Re: Strategy for optionally excluding a named method parameter? Thread-Topic: RE: Re: Strategy for optionally excluding a named method parameter? To: "users@groovy.apache.org" , "users@groovy.apache.org" , David Karr Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8"

Both named and varag

 

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

print args.two }

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

f(one:"string", two:true)

f(two:= false)

f(two:true)

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

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

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

 

[string]

[false][string]

[true][null]

[false][null]

[true][null]

[false][null]

[true][null]

[false]

<= o:p> 

Please as a work around keep the <= b>boolean as the last parameter. Since map is a subclass of =C2= =A0Object, 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 way to go!

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

T.Rathina= velu

 

Sent= from Mail= for Windows 10

 

From: MG
Sent: Sunday, April 26, 2020 5:00 AM
To: users@groovy.apache.org; David Karr
Subject: Re: Strategy for optionall= y excluding a named method parameter?

&n= bsp;

Hi David,=

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

= Cheers,
mg

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

 

 

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

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

Kindly mail me an use-case.

T= .Rathinavelu

&nb= sp;

The code sample looks somethin= g like this:

 

    functionName param1= : value,

   &n= bsp;    param2: value,

        param3: value,

      &= nbsp; param4: value,

 &n= bsp;      ...

        param25: value

 

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

 

    functionName= param1: value,

  &= nbsp;     param2: value,

        param3: value,

      = ;  ...

   &nbs= p;    param25: value

 

Where the "= ;param4" key and value are not provided.  Presently, we have an &= quot;if" checking for a condition, followed by the "true" bl= ock with the first version of the function call with 25 parameters, followe= d by the "else" and the "false" block with the second v= ersion, which has 24 parameters, all the same values as in the first block,= except for the one key and value not provided in the second version.<= /o:p>

 

<= blockquote style=3D'border:none;border-left:solid #CCCCCC 1.0pt;padding:0in= 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'>

 <= /p>

Sent from Mail for Windows 10

 

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

 

L= ately my only Groovy work is scripted pipelines in Jenkins, version 2.89.4 = .

 

I'm working with an api = that is somewhat dumb in one respect.  The method we call takes ~25 pa= rameters.  We send them as named parameters. One of the parameters is = of boolean type.  What we've discovered from testing is that if we sen= d a value as either "true" or "false", it acts as if we= sent "true".  If we construct the call without that paramet= er entirely, it acts as if we sent "false". I tried making it sen= d null, but that just causes it to fail at runtime.  We presently have= an "if" for that one flag, with two calls to the method, one tak= ing 25 parameters, the other taking 24.  It is really obnoxious.

 

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

 

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

 

 

 

 

=