groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-8899) Add DGSM `first` and `last`
Date Mon, 26 Nov 2018 15:49:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8899?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16699171#comment-16699171
] 

Eric Milles edited comment on GROOVY-8899 at 11/26/18 3:48 PM:
---------------------------------------------------------------

Isn't this the existing JDK form for getting the first element?
{code:java}
Stream.of(...).findFirst().get()
{code}

I agree with [~blackdrag] that a DGM for Stream could shorten this to:
{code:groovy}
Stream.of(...).first()
{code}

or what about this (supported by {{getAt(Stream,int)}})?
{code:groovy}
Stream.of(...)[0] // first
Stream.of(...)[-1] // last
{code}


was (Author: emilles):
Isn't this the existing JDK form for getting the first element?
{code:java}
Stream.of(...).findFirst().get()
{code}

I agree with [~blackdrag] that a DGM for Stream could shorten this to:
{code:groovy}
Stream.of(...).first()
{code}

or what about this (supported by {getAt(Stream,int)})?
{code:groovy}
Stream.of(...)[0] // first
Stream.of(...)[-1] // last
{code}

> Add DGSM `first` and `last`
> ---------------------------
>
>                 Key: GROOVY-8899
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8899
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Daniel Sun
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 3.0.0-alpha-4
>
>
> {code:java}
>     void testFirst() {
>         assert 2 == Stream.of(2, 3, 6, 5).collect(Collectors.first()).get()
>     }
>     void testLast() {
>         assert 5 == Stream.of(2, 3, 6, 5).collect(Collectors.last()).get()
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message