commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: [collections] New iterator/iterable methods
Date Fri, 12 Jan 2018 00:51:08 GMT
On Thu, Jan 11, 2018 at 5:23 PM, sebb <sebbaz@gmail.com> wrote:

> On 11 January 2018 at 15:22, Gary Gregory <garydgregory@gmail.com> wrote:
> > Hi,
> >
> > Some APIs, either due to age or design, deal out an Iterator and nothing
> > else. And sometimes, all I care about (in tests, for example, or if the
> > list is a set of aliases) is the first object.
> >
> > The method IteratorUtils.first(Iterator) is a shorthand for
> > IteratorUtils.get(Iterator, 0).
>
> The code method is only shorter by one character and that is a space.
>
> This will just add unnecessary code and maintenance costs.
>

I do not look at it that way. I see it at providing an abstraction that
says "give me the first element" instead of "give me the 0th element". Code
reads better that way. IMO.

What maintenance costs are referring to here?

Gary



>
> > I do not plan to add last(), the obvious sibling to such a method, YAGNI
> > for now.
> >
> > Gary
> >
> >
> > On Thu, Jan 11, 2018 at 2:52 AM, sebb <sebbaz@gmail.com> wrote:
> >
> >> Also, what is the use case for such methods?
> >> How many will there be - i.e. do you plan to add .last, .second,
> .random?
> >>
> >> I'm not keen on methods that save a few lines of code unless there's a
> >> common use case and the behaviour is obvious/unambiguous from the
> >> name.
> >>
> >> On 11 January 2018 at 07:45, Claude Warren <claude@xenei.com> wrote:
> >> > does first return the first object or the first non-null object?
> >> >
> >> > If the first object how do you distinguish between first() returning a
> >> null
> >> > object and there being an empty container?
> >> > If the first non-null object how do you determine that nulls were
> >> skipped?
> >> >
> >> > Keep in mind that the Optional implementation in Java8 will throw an
> >> > exception if it is constructed with a null object.
> >> >
> >> > On Wed, Jan 10, 2018 at 4:45 PM, Gary Gregory <garydgregory@gmail.com
> >
> >> > wrote:
> >> >
> >> >> Hi All,
> >> >>
> >> >> I plan on adding methods like:
> >> >> - IteratorUtils.first(Iterator)
> >> >> - IterableUtils.first(Iterable)
> >> >>
> >> >> Gary
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > I like: Like Like - The likeliest place on the web
> >> > <http://like-like.xenei.com>
> >> > LinkedIn: http://www.linkedin.com/in/claudewarren
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: dev-help@commons.apache.org
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message