Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9C8A6200CB0 for ; Fri, 9 Jun 2017 02:15:23 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9B06C160BE5; Fri, 9 Jun 2017 00:15:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E261F160BD5 for ; Fri, 9 Jun 2017 02:15:22 +0200 (CEST) Received: (qmail 4374 invoked by uid 500); 9 Jun 2017 00:15:22 -0000 Mailing-List: contact notifications-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 notifications@groovy.apache.org Received: (qmail 4365 invoked by uid 99); 9 Jun 2017 00:15:22 -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; Fri, 09 Jun 2017 00:15:22 +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 A268A188A97 for ; Fri, 9 Jun 2017 00:15:21 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -98.702 X-Spam-Level: X-Spam-Status: No, score=-98.702 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_NUMSUBJECT=0.5, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 1iU4z4Zoxljo for ; Fri, 9 Jun 2017 00:15:20 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 107C05FB71 for ; Fri, 9 Jun 2017 00:15:20 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 50E96E065D for ; Fri, 9 Jun 2017 00:15:19 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 4268C21E0C for ; Fri, 9 Jun 2017 00:15:18 +0000 (UTC) Date: Fri, 9 Jun 2017 00:15:18 +0000 (UTC) From: "Paul King (JIRA)" To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (GROOVY-6744) Have the elvis operator (?:) support the Optional type in Java 8 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 09 Jun 2017 00:15:23 -0000 [ https://issues.apache.org/jira/browse/GROOVY-6744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16043661#comment-16043661 ] Paul King edited comment on GROOVY-6744 at 6/9/17 12:14 AM: ------------------------------------------------------------ Marked as a breaking change for anyone relying on the old behavior. If you were working around the old behavior using the ternary operator, i.e.: {code} def empty = Optional.empty() def foo = Optional.of('foo') def bar = Optional.of('bar') assert foo.isPresent() ? foo : bar == foo assert empty.isPresent() ? empty : bar == bar {code} you can leave your code unchanged or change to the more compact elvis operator notation version: {code} assert foo ?: bar == foo assert empty ?: bar == bar {code} was (Author: paulk): Marked as a breaking change for anyone relying on the old behavior. If you were working around the old behavior using the ternary operator, i.e.: {code} def empty = Optional.empty() def foo = Optional.of('foo') def bar = Optional.of('bar') assert foo.isPresent() ? foo : bar == foo assert empty.isPresent() ? empty : bar == bar {code} you can leave your code unchanged or change to the more compact: {code} assert foo ?: bar == foo assert empty ?: bar == bar {code} > Have the elvis operator (?:) support the Optional type in Java 8 > ---------------------------------------------------------------- > > Key: GROOVY-6744 > URL: https://issues.apache.org/jira/browse/GROOVY-6744 > Project: Groovy > Issue Type: New Feature > Components: Compiler > Reporter: Aadi Deshpande > Assignee: John Wagenleitner > Labels: breaking > Fix For: 2.5.0-beta-1 > > > With Java 8 and the rising popularity of Optional type in lieu of null management, it would be great if Groovy's elvis could handle Optional in the same way. > {code:java} > Optional string1 = Optional.of("foo") > Optional string2 = Optional.empty() > assert "foo" == ( string1 ?: "bar" ) > assert "bar" == ( string2 ?: "bar" ) > {code} > Conversely, another option is to make elvis overloadable. ( something like {{orElse()}} ). > That way, other Option/al types ( i.e. from Guava or FJ ) can have extension methods to support their use as well. -- This message was sent by Atlassian JIRA (v6.3.15#6346)