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).

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 <seb...@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 <cla...@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 <garydgreg...@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-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
>
>

Reply via email to