[ 
https://issues.apache.org/jira/browse/JENA-1427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16263306#comment-16263306
 ] 

Andy Seaborne commented on JENA-1427:
-------------------------------------

If we add to {{ExtendedIterator}}, these are the possible operations:

* {{nextOptional}}
* {{nextOrElse}}
* {{nextOrElseGet}}
* {{nextOrElseThrow}}

where the {{nextOrElse*}} are functionally like {{nextOptional().orElse*}} 
methods (all as default methods, the {{nextOrElse*}} not implemented as 
"optional.orElse").

with an open question about whether the {{nextOrElse*}} are really necessary 
(albeit shorter).

This seems like relatively low risk extension to the API. While generally, I am 
nervous about tinkering with the main API because changes/additions are usually 
opinionated, hence implicitly saying "and don't extend <other way/style>", 
these operations don't fall into this category.

Would that work?


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

Reply via email to