groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Rodent (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-8565) Method from java.util.Deque to be added to Groovy List?
Date Fri, 04 May 2018 17:04:00 GMT

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

Mike Rodent edited comment on GROOVY-8565 at 5/4/18 5:03 PM:
-------------------------------------------------------------

Thanks.

Yes, I was meaning a "bog standard" (POGO?) List.

The only one that hadn't occurred to me is
{code:java}
def list3 = [3] + list2 // addFirst(3){code}
... but that also doesn't satisfy because one has to make the element into a List artificially.

I just think this is a "lacuna"... Groovy is so goddam cleverly conceived and executed there's
no excuse for not having a parameterless way of adding and removing an element at the start
of a POGO List (IMHO!).

 what about
{code:java}
el >> myList{code}
to prepend for example?

Of course, if the proposed change to `pop()` and `push()` happen, in Groovy 3 (and if you
look it up it is actually going happen in Groovy 2.5), that will solve my issue, but also
leave a lacuna: you'll be able to append with `<<`, but how then to remove the last
element in parameterless fashion?

Course, there is already `drop`, but you have to give it a parameter (Integer).  Could it
be overloaded to provide a parameterless version?  I think that would be confusing: it would
look like the entire List was being "dropped".

I conclude: `addLast` and `removeLast`.  Simple, clear, easy-peasy.  Jolly convenient.

 

 

 


was (Author: mrodent):
Thanks.

Yes, I was meaning a "bog standard" (POGO?) List.

The only one that hadn't occurred to me is
{code:java}
def list3 = [3] + list2 // addFirst(3){code}
... but that also doesn't satisfy because one has to make the element into a List artificially.

I just think this is a "lacuna"... Groovy is so goddam cleverly conceived and executed there's
no excuse for not having a parameterless way of adding and removing an element at the start
of a POGO List (IMHO!).

 what about 
{code:java}
el >> myList{code}
to prepend for example?

Of course, if the proposed change to `pop()` and `push()` happen, in Groovy 3 (and if you
look it up it is actually going happen in Groovy 2.5), that will solve my issue, but also
leave a lacuna: you'll be able to append with `<<`, but how then to remove the last
element in parameterless fashion?

Course, there is already `drop`, but you have to give it a parameter (Integer).  Could it
be overloaded to provide a parameterless version?

 

 

 

> Method from java.util.Deque to be added to Groovy List?
> -------------------------------------------------------
>
>                 Key: GROOVY-8565
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8565
>             Project: Groovy
>          Issue Type: New Feature
>            Reporter: Mike Rodent
>            Priority: Minor
>
> I was surprised to find that List in the GDK hasn't added `addFirst` method. AKA `shift`. 
Also `removeFirst` AKA `unshift`.
> I'm intrigued to see that in Groovy 3.0.0 (not in beta at time of writing) `push` and
`pop` *appear* to be changing from adding/removing at the end, as currently, to adding/removing
at the *beginning*, "to align with java.util.Stack".  So can we conclude that the need for
more stack/queue/deque methods has been recognised?
> Of course there are multiple ways of doing this... it's just that that means that it's
slightly less convenient to use a standard Groovy List as an interesting form of queue or
deque.  What you really want is parameterless methods for these standard queue-type operations.
> java.util.Deque has some other interesting methods which one might want to think about
too: offerXXX, peekXXX, getXXX.



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

Mime
View raw message