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] [Commented] (GROOVY-8899) Add DGSM `first` and `last`
Date Mon, 26 Nov 2018 16:51:00 GMT

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

Eric Milles commented on GROOVY-8899:
-------------------------------------

If you want to do it all in one continuous sequence, sure you'll need support.  But can't
you do this:
{code:groovy}
IntStream stream = IntStream.of(1, 2, 3, 4)
int first = stream[0]
int last = stream[-1]
{code}

How common is the case of needing both the first and last elements of a stream only?  With
the JDK support, you can toArray() the stream and then index the first and last elements.
 I'm not saying the collector additons are not useful in some circumstances.  I'm offering
some additional DGMs that could be useful and save the need for collect() and Collectors,
which I personally find very cumbersome.

> 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