[
https://issues.apache.org/jira/browse/JENA-1427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16272757#comment-16272757
]
ASF GitHub Bot commented on JENA-1427:
--------------------------------------
Github user ajs6f commented on the issue:
https://github.com/apache/jena/pull/323
Do we want to return `empty` for `null`? I ask because the "ergonomics" are
different. The way we have it now:
```
try {
iterator.nextOptional().ifPresent(this::doStuff);
}
catch (NullPointerException e) { worry about that; }
```
vs. just `iterator.nextOptional().ifPresent(this::doStuff);` where
`doStuff` is responsible for testing for `null`. I actually like the latter
because `null` might be a legitimate value, but I may be misunderstanding the
contract of `ExtendedIterator`-- is it guaranteed that `next()` never returns
`null`? Is `null` actually not ever legit?
> 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)