I agree. I think it might be valuable to suggest a peek() like method for
iterators but that is a different kettle of fish.
Jena has an ExtendedIterator that provides some extra functionality (like
mapping and filtering as well as converting to lists or sets). In a class
like that might be handy
This use case reminds me of how both Scala and Kotlin have structured their
collections classes. Here are some comparisons.
Kotlin adds a .first() extension function for multiple collection classes: <
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/first.html>
Do note the lack of
first(Iterator/Iterable) is shorthand for get(Iterator/Iterable, 0), so the
Javadocs is much like get().
My current use case is to replace:
aSet.iterator().next()
with:
first(aSet)
Gary
On Fri, Jan 12, 2018 at 12:43 AM, Claude Warren wrote:
> actually last() would probably be more useful.
actually last() would probably be more useful. I still don't see the need
for first() when next() will suffice, unless first() is changing the return
value when there is no first().
As clarification what happens if I call:
Iterator iterator = Arrays.asList( "a","b" ).iterator();
x = IteratorUtil
On 12 January 2018 at 00:51, Gary Gregory wrote:
> On Thu, Jan 11, 2018 at 5:23 PM, sebb wrote:
>
>> On 11 January 2018 at 15:22, Gary Gregory 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,
On Thu, Jan 11, 2018 at 5:23 PM, sebb wrote:
> On 11 January 2018 at 15:22, Gary Gregory 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 th
On 11 January 2018 at 15:22, Gary Gregory 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
for test cases I tend to use iterator.next() to get the first item. It
will fail spetacularly if the iterator has no next() and if it does you
have first(). No need for extra functions.
Claude
On Thu, Jan 11, 2018 at 3:22 PM, Gary Gregory
wrote:
> Hi,
>
> Some APIs, either due to age or desig
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
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
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 impleme
Hi All,
I plan on adding methods like:
- IteratorUtils.first(Iterator)
- IterableUtils.first(Iterable)
Gary
12 matches
Mail list logo