From users-return-4314-apmail-groovy-users-archive=groovy.apache.org@groovy.apache.org Sat Apr 25 23:59:09 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 6353119E26 for ; Sat, 25 Apr 2020 23:59:09 +0000 (UTC) Received: (qmail 37230 invoked by uid 500); 25 Apr 2020 23:59:08 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 37192 invoked by uid 500); 25 Apr 2020 23:59:08 -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 37182 invoked by uid 99); 25 Apr 2020 23:59:08 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Apr 2020 23:59:08 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id B2228181A77 for ; Sat, 25 Apr 2020 23:59:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.303 X-Spam-Level: * X-Spam-Status: No, score=1.303 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, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-ec2-va.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id QW3D0MiQCwEt for ; Sat, 25 Apr 2020 23:59:06 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.216.45; helo=mail-pj1-f45.google.com; envelope-from=rathinavelu@gmail.com; receiver= Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by mx1-ec2-va.apache.org (ASF Mail Server at mx1-ec2-va.apache.org) with ESMTPS id 3125CBB8FE for ; Sat, 25 Apr 2020 23:59:06 +0000 (UTC) Received: by mail-pj1-f45.google.com with SMTP id hi11so5702219pjb.3 for ; Sat, 25 Apr 2020 16:59:06 -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=t0rTEAfB92XOcLvIRHlkiQaRTYhwF/h+hgxwrLIIG/0=; b=qMYtvXmOOCA/TA5KCblluXwKAQSpbFHta0DBEndpzj3cbrqqdvLbwJr8XBuN3QWJeH //hLOrm2rz3bZZcRm2B/EohF5ZhP9httNGmlg45VSVj0o5U8c2cLhl5TXo31METlPXTJ x30jcdWoqgV8jx56mZ5rm5NerirDuBX/NkKOPY61e1YIcDUCJUkltGfYNNiKA54wgujY gR7TmtCu0Ek2jgqi6ceonnbHXwNU5OwasNrvzBeaTpRWLwJMNS6C5xM12J29rvr2VIle 6Q2K6Mzrve4afVh7S09Hvr9h1kj6tXBVm/zJBxAeEThMQr6P/WuS2MHVY29tS/pkRGV/ bJrw== 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=t0rTEAfB92XOcLvIRHlkiQaRTYhwF/h+hgxwrLIIG/0=; b=QuvdNqrb47DvLqMff45IuhN4FImWapxju5CIyHjvi3QWykSylCTSbrbm0q68Brq1OR 8gl15pXuGoK8+aIsUy7V8rOqMsURMhTEnjXAaAj0zt2+9YxMbjWwZHzobHdARHgiGuLF hKtnPht8r+xTw1YQnB/4BcpdXUIKATa6XaPD/0m3n0N8DhoMj6s2kP3I2GB5hrkPbpxb RQ80rdQiVbIRJ28tqJEeJBy2k+fbYycbYo4ws6ewj47OyTGsTAZdhwgQhy5NGgYyCUV+ GPfxXKLdAP8KWbI7TTmmkkZSb2iSVTY+K9FIzXoxS+fzBO6h1QQaM84f7ysulrEuS0nZ WAfA== X-Gm-Message-State: AGi0PuaEvnbeHC1Lu/8J8rdQ9TR6CydcqoEB/9noNWqmBFSG9c1U1dgO Xk23amsG5IgZe6Q2G0H27UG4unqO8Tk= X-Google-Smtp-Source: APiQypIBHG6GfX4dXDGMsMtL4JsH6nroeIVJGJgZ+EmBwtdU6/AW4rkn1tnJZJ8auqLtCm3tzrW4QQ== X-Received: by 2002:a17:90a:1501:: with SMTP id l1mr14725859pja.82.1587859144967; Sat, 25 Apr 2020 16:59:04 -0700 (PDT) Received: from smtp.gmail.com ([2405:201:e808:1fea:8140:6e9:6392:c74a]) by smtp.gmail.com with ESMTPSA id b9sm8748371pfp.12.2020.04.25.16.59.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Apr 2020 16:59:04 -0700 (PDT) Message-ID: <5ea4cec8.1c69fb81.99e97.0ece@mx.google.com> MIME-Version: 1.0 Date: Sun, 26 Apr 2020 05:28:58 +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" Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8"

Sirs,

1.We need both named parameters implemented through map and= , also varags if we want to call with different numbers of arguments= , here 25 as well as 24.

varag= s has the syntax

 

<= p class=3DMsoListParagraph>def foo(Object... args)=C2=A0 // same as def = foo(Object[] args)

 = ;

2.As for .  =E2=80=A6What we= 've discovered from testing is that if we send a value as either "true= " or "false", it acts as if we sent "true".&nb= sp;=E2=80=A6=C2=A0 for me it does not happen; I get the correct response as= below.

 

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 de= f g(Map map){ println !map.one}=C2=A0 // I have complemented the pas= sed parameter ! map.one

=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 g(one:false)

<= p class=3DMsoNormal>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 g(one:true)

 

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 The output is :

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

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

Thanking you,

T.Rath= inavelu

Sent from Mail for Windows 10

 

From: MG
Sent: Sunday, April 26, 2020 5:00 AM
= To: users@groovy.apache.org<= /a>; David Karr
Sub= ject: Re: Strategy for optionally excluding a named method parameter?

 

Hi David,

since, as was mentioned, named = parameters are implemented as a map underneath in Groovy, you should be abl= e to remove the map entry of the parameter 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@gm= ail.com> wrote:

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

Kindly= mail me an use-case.

T.Rathinavelu

<= div>

 

The code sample looks something like this:

 

 = ;   functionName param1: value,

        param2: value,=

     &nb= sp;  param3: value,

&nbs= p;       param4: value,

<= div>

        ...

     &n= bsp;  param25: value

 

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

 

    functionName param1: value,

<= p class=3DMsoNormal>        param2: valu= e,

    &n= bsp;   param3: value,

&n= bsp;       ...

        param25: value=

 

<= p class=3DMsoNormal>Where the "param4" key and value are not prov= ided.  Presently, we have an "if" checking for a condition, = followed by the "true" block with the first version of the functi= on call with 25 parameters, followed by the "else" and the "= false" block with the second version, which has 24 parameters, all the= same values as in the first block, except for the one key and value not pr= ovided in the second version.

 

 

Sent from Mail for Win= dows 10

 

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

 

Lately my only Groovy work is scripted pi= pelines in Jenkins, version 2.89.4 .

 

<= div>

I'm working with an api that is somewhat dumb in one respect.&nb= sp; The method we call takes ~25 parameters.  We send them as named pa= rameters. One of the parameters is of boolean type.  What we've discov= ered from testing is that if we send a value as either "true" or = "false", it acts as if we sent "true".  If we cons= truct the call without that parameter entirely, it acts as if we sent "= ;false". I tried making it send null, but that just causes it to fail = at runtime.  We presently have an "if" for that one flag, wi= th two calls to the method, one taking 25 parameters, the other taking 24.&= nbsp; It is really obnoxious.

 

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

 

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

 

 

 

 =