From dev-return-5509-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Thu Oct 18 19:17:26 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1FEA418064E for ; Thu, 18 Oct 2018 19:17:24 +0200 (CEST) Received: (qmail 53555 invoked by uid 500); 18 Oct 2018 17:17:24 -0000 Mailing-List: contact dev-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list dev@groovy.apache.org Received: (qmail 53543 invoked by uid 99); 18 Oct 2018 17:17:23 -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; Thu, 18 Oct 2018 17:17:23 +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 26B23180790 for ; Thu, 18 Oct 2018 17:17:23 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3 X-Spam-Level: *** X-Spam-Status: No, score=3 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id Y4k9JyZpIBYx for ; Thu, 18 Oct 2018 17:17:21 +0000 (UTC) Received: from smtp2.czechia.com (smtp2.czechia.com [217.198.120.64]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 20DD65F170 for ; Thu, 18 Oct 2018 17:17:20 +0000 (UTC) Received: from [10.0.0.140] (unknown [77.240.103.197]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: ocs@ocs.cz) by smtp2.czechia.com (Postfix) with ESMTPSA id 7A5B88165A43 for ; Thu, 18 Oct 2018 19:17:14 +0200 (CEST) From: "ocs@ocs" Content-Type: multipart/alternative; boundary="Apple-Mail=_A8776359-22C1-4152-9484-4686ABAFF9D4" Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: DGM for first or default Date: Thu, 18 Oct 2018 19:17:13 +0200 References: To: dev@groovy.apache.org In-Reply-To: Message-Id: X-Mailer: Apple Mail (2.3445.9.1) --Apple-Mail=_A8776359-22C1-4152-9484-4686ABAFF9D4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 P.S. Oh, and when I am writing anyway =E2=80=94 please, do not abuse the = =E2=80=9Coverloaded=E2=80=9D methods which differ just by their argument = lists (myself, I consider them always at best suspicious; mostly plain = wrong). Instead of the suggestion below, if something like that is = accepted, it would be much better to change the method name = appropriately (say, e.g., firstWithDefault, firstWithSupplier). Or = perhaps named arguments might be (consistently!) used for these things = (e.g., =E2=80=9Cfirst(default:value)=E2=80=9D or = =E2=80=9Cfirst(supplier:value)=E2=80=9D). Consider e.g., an array of closures, of which one would want to get the = first one with a default closure... with the definitions suggested below = that's going to be fun! All the best, OC > On 18 Oct 2018, at 5:39 PM, Milles, Eric (TR Technology & Ops) = wrote: >=20 > I see there are the following DGMs for getting first element of a = "collection": > static T first(T[] self) > static T first(List self) > static T first(Iterable self) >=20 > Is there a simple sequence for getting the first element or a default = value if the "collection" is empty? If not, may I propose the addition = of the following DGMs: > static T first(T[] self, T defaultValue) > static T first(List self, T defaultValue) > static T first(Iterable self, T defaultValue) > static T first(T[] self, Closure defaultSupplier) > static T first(List self, Closure defaultSupplier) > static T first(Iterable self, Closure defaultSupplier) >=20 >=20 > Eric M. --Apple-Mail=_A8776359-22C1-4152-9484-4686ABAFF9D4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 P.S. = Oh, and when I am writing anyway =E2=80=94 please, do not abuse the = =E2=80=9Coverloaded=E2=80=9D methods which differ just by their argument = lists (myself, I consider them always at best suspicious; mostly plain = wrong). Instead of the suggestion below, if something like that is accepted, it would be much = better to change the method name appropriately (say, e.g., = firstWithDefault, firstWithSupplier). Or perhaps named arguments might = be (consistently!) used for these things (e.g., = =E2=80=9Cfirst(default:value)=E2=80=9D or = =E2=80=9Cfirst(supplier:value)=E2=80=9D).

Consider e.g., an array = of closures, of which one would want to get the first one with a default = closure... with the definitions suggested below that's going to be = fun!

All the = best,
OC

On 18 = Oct 2018, at 5:39 PM, Milles, Eric (TR Technology & Ops) <eric.milles@thomsonreuters.com> wrote:

I see there are the following DGMs for = getting first element of a "collection":

  static <T> T first(T[] self)
  static <T> T first(List<T> self)
  = static <T> T first(Iterable<T> self)


Is= there a simple sequence for getting the first element or a default = value if the "collection" is empty?  If not, may I propose = the addition of the following DGMs:

  static <T> T first(T[] self, T defaultValue)
  static <T> T first(List<T> self, T defaultValue)

  static <T> T first(Iterable<T> self, T defaultValue)

  = static <T> T first(T[] self, Closure<T>= defaultSupplier)
  static <T> T first(List<T> self, Closure<T>= defaultSupplier)

  static <T> T first(Iterable<T> self, Closure<T>= defaultSupplier)


Eric = M.

= --Apple-Mail=_A8776359-22C1-4152-9484-4686ABAFF9D4--