Re: [collections] New iterator/iterable methods

2018-01-13 Thread Claude Warren
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

Re: [collections] New iterator/iterable methods

2018-01-12 Thread Matt Sicker
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

Re: [collections] New iterator/iterable methods

2018-01-12 Thread Gary Gregory
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.

Re: [collections] New iterator/iterable methods

2018-01-11 Thread Claude Warren
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

Re: [collections] New iterator/iterable methods

2018-01-11 Thread sebb
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,

Re: [collections] New iterator/iterable methods

2018-01-11 Thread Gary Gregory
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

Re: [collections] New iterator/iterable methods

2018-01-11 Thread sebb
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

Re: [collections] New iterator/iterable methods

2018-01-11 Thread Claude Warren
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

Re: [collections] New iterator/iterable methods

2018-01-11 Thread Gary Gregory
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

Re: [collections] New iterator/iterable methods

2018-01-11 Thread sebb
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

Re: [collections] New iterator/iterable methods

2018-01-10 Thread Claude Warren
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

[collections] New iterator/iterable methods

2018-01-10 Thread Gary Gregory
Hi All, I plan on adding methods like: - IteratorUtils.first(Iterator) - IterableUtils.first(Iterable) Gary