From users-return-4315-apmail-groovy-users-archive=groovy.apache.org@groovy.apache.org Sun Apr 26 00:01:13 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 4D85919E47 for ; Sun, 26 Apr 2020 00:01:13 +0000 (UTC) Received: (qmail 40912 invoked by uid 500); 26 Apr 2020 00:01:12 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 40862 invoked by uid 500); 26 Apr 2020 00:01:12 -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 40852 invoked by uid 99); 26 Apr 2020 00:01:12 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Apr 2020 00:01:12 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id A52BBC00AF for ; Sun, 26 Apr 2020 00:01:11 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-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: spamd1-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 (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 4AFDtXvdEoqk for ; Sun, 26 Apr 2020 00:01:09 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.215.174; helo=mail-pg1-f174.google.com; envelope-from=rathinavelu@gmail.com; receiver= Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by mx1-ec2-va.apache.org (ASF Mail Server at mx1-ec2-va.apache.org) with ESMTPS id 3549EBB8FE for ; Sun, 26 Apr 2020 00:01:09 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id r4so6682467pgg.4 for ; Sat, 25 Apr 2020 17:01:09 -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=+EqWBBPQgG5Pi8ZaJdiVnHpJ2gWR8Bk9kJr66pluxvQ=; b=NVcz10xsvZhtU+2LYa1HSDNGA7+GoRXpvSBXJq6wkL4aZw0bar9Mxf7g6LDyv+VtF8 kTw+SHfKjjdXLgHJon8SaexZxQ46MvQRh70JvX3031+NaV44/COHWsf+jUKxIqOxbM1H rjLqelNVkSWq06QFigB0qL8K2KYcojECRooB5pY6YzXD8lSYchoYpuaznW2mnKxEWLkF y0ivHIIGLoHEGZXSdqSXw3AEmtOLz5BRjHUOk27SCX+STZpOxentIAayND94bx5OpwPU 3Qkcw8kyN9+iDZb6gR+ZqJcE0qo+undocbx2hQvn43bXkLba3fYk8qx+r5WQFTWdKzYB XhvQ== 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=+EqWBBPQgG5Pi8ZaJdiVnHpJ2gWR8Bk9kJr66pluxvQ=; b=FbAOK9eMzNj2f5hN4lmcQ81rxN9WtJyYv0QLZK8ZLIlFixpP4vBMRgomQNPYDbt0bE 1cersyjZQyVm1Wq11IiUQhXhZsOEnPNRPBZWW97hV/B8BY+gyV8SssJ+xEFu2hjS7XQ8 WrymplWagbF+5bLP8fjDCyKD6PnTMHeVghmYYmS1SoYy+YsM+si98teh1JodhPnELN8p PZMB6CXraVYJhwkd8DzHwDFZy1q55IqeSj+W2OEai2V3svnIFrk1i5FN5MzXwA3pWmao I8qR6c7f4F1h3TKLx1SuDXzpH4vJ04Dpto/ATt09GniMn40dqc/uKBMuvwE/A2oUKKkK JHXQ== X-Gm-Message-State: AGi0PuYGSZUSDeHXm+8KlHUZjsfl1K7m9VpcPjZ/7/qqn/H7V2FhiE+k ROlm7Q5opcW0xaQFGvnxnjCycgNN8L4= X-Google-Smtp-Source: APiQypLcObtRDAaU6E22JIsluj5+Ln4l0PgmPPS5mMPjoPnvwavsg+aiAh0e8MecHB3iPDZVBMZldQ== X-Received: by 2002:a63:5125:: with SMTP id f37mr16111159pgb.327.1587859261913; Sat, 25 Apr 2020 17:01:01 -0700 (PDT) Received: from smtp.gmail.com ([2405:201:e808:1fea:8140:6e9:6392:c74a]) by smtp.gmail.com with ESMTPSA id b15sm8926127pfd.139.2020.04.25.17.01.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Apr 2020 17:01:01 -0700 (PDT) Message-ID: <5ea4cf3d.1c69fb81.bbc6f.00ea@mx.google.com> MIME-Version: 1.0 Date: Sun, 26 Apr 2020 05:30:56 +0530 From: Rathinavelu Subject: FW: RE: Re: Strategy for optionally excluding a named method parameter? Thread-Topic: FW: RE: Re: Strategy for optionally excluding a named method parameter? To: "users@groovy.apache.org" , David Karr Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8"

 

 

Sent from Mail for Windows 10

 

=

From: Rathinavelu
Sent: Sunday, A= pril 26, 2020 5:29 AM
To: users@groovy.apache.org
Subject: RE: Re: Strategy for opt= ionally excluding a named method parameter?

<= o:p> 

Sirs,

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

var= ags has the syntax

 

def foo(Object... args)  // same as de= f foo(Object[] args)

&nb= sp;

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

 

            = def g(Map map){ println !map.one}  // I have complemented the p= assed parameter ! map.one

 &= nbsp;          g(one:false)

       =      g(one:true)

 

      =       The output is :

           &n= bsp; true

     =         false

Thanking you,

T.Rathinavelu

Sent from Mail for Windows 10

 

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

 = ;

Hi David,
since, as was mentioned, named parameters are implemented as a map und= erneath in Groovy, you should be able to remove the map entry of the parame= ter you do not want to pass, though I did not try this myself...

Che= ers,
mg

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

 

 

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

Named parameters are not avai= lable 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 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.<= /p>

T.Rathinavelu

 

The code sample looks something like this:

 

    functionName param1: value,

        param2: v= alue,

    = ;    param3: value,

        param4: value,<= /p>

      &nbs= p; ...

   &nbs= p;    param25: value

 

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

 

    functionName param1: value,

<= /div>

        p= aram2: value,

  &nb= sp;     param3: value,

        ...

        param25: v= alue

 

Where the "param4" key and value are= not provided.  Presently, we have an "if" checking for a co= ndition, followed by the "true" block with the first version of t= he function call with 25 parameters, followed by the "else" and t= he "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 val= ue not provided in the second version.

 

 

Sent from = Mail for Windows 10

 <= o:p>

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?

 

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

 

I'm working wi= th an api that is somewhat dumb in one respect.  The method we call ta= kes ~25 parameters.  We send them as named parameters. One of the para= meters is of boolean type.  What we've discovered from testing is that= if we send a value as either "true" or "false", it act= s as if we sent "true".  If we construct the call without th= at parameter entirely, it acts as if we sent "false". I tried mak= ing it send null, but that just causes it to fail at runtime.  We pres= ently have an "if" for that one flag, with two calls to the metho= d, one taking 25 parameters, the other taking 24.  It is really obnoxi= ous.

 

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

=

 

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

=

 

 

 

&= nbsp;

 

=