[
https://issues.apache.org/jira/browse/JENA-1427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16257303#comment-16257303
]
A. Soroka commented on JENA-1427:
---------------------------------
This seems like it could be a twist on the method
{{org.apache.jena.atlas.iterator.Iter.first(Iterator<T>)}}, something like:
{code}
/** Return the first element of an iterator if available.
* @param iter
* @return An item if present.
*/
public static <T> Optional<T> first(Iterator<T> iter) {
return Optional.ofNullable(first(iter));
}
{code}
It definitely sounds like you are reaching for {{Optional}}.
> Add nextOrElse() method in ExtendedIterator
> -------------------------------------------
>
> Key: JENA-1427
> URL: https://issues.apache.org/jira/browse/JENA-1427
> Project: Apache Jena
> Issue Type: Improvement
> Components: Core
> Affects Versions: Jena 3.5.0
> Reporter: Adam Jacobs
> Priority: Trivial
> Labels: easytask
>
> Allow a functional approach for returning a default value or throwing a
> custom exception from a Jena iterator.
> The following method may be added to the ExtendedIterator interface.
> {noformat}
> /**
> Answer the next object, if it exists, otherwise invoke the
> _supplier_.
> */
> public default T nextOrElse( Supplier<T> supplier ) {
> return hasNext() ? next() : supplier.get();
> }
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)