groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Sun (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8899) Add DGSM `first` and `last`
Date Fri, 23 Nov 2018 15:15:00 GMT

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

Daniel Sun commented on GROOVY-8899:
------------------------------------

[~blackdrag] Sorry, I saw your comment just now...

We can use the collector like some window function of Oracle, e.g.

{code:java}
    void testFirstAndLast() {
        Tuple2<Integer, Integer> firstAndLastTuple =
                Stream.of(2, 3, 6, 5)
                        .collect(Tuple.collectors(Collectors.first(), Collectors.last()))
                        .map1(Optional::get).map2(Optional::get)
        assert Tuple.tuple(2, 5) == firstAndLastTuple
    }
{code}
( https://github.com/apache/groovy/blob/43c75a23f43dc8968471927fd8a7d8119290d7ec/src/test/org/codehaus/groovy/runtime/DefaultGroovyStaticMethodsTest.groovy#L45
)

I always want to implement a LINQ for groovy(we can name it as GINQ), which will rely on many
window functions. Luckily, JOOL( https://github.com/jOOQ/jOOL, licensed under APL2) gives
us many examples to study and borrow.

 

> 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