You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commonsrdf.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/04/10 11:41:12 UTC
[jira] [Commented] (COMMONSRDF-12) Graph to be Iterable
[ https://issues.apache.org/jira/browse/COMMONSRDF-12?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14489270#comment-14489270 ]
ASF GitHub Bot commented on COMMONSRDF-12:
------------------------------------------
GitHub user stain opened a pull request:
https://github.com/apache/incubator-commonsrdf/pull/8
COMMONSRDF-12 Graph implements Iterable interface
..with a `default` method that simply calls `getTriples().iterator()`
This is mainly to be useful for classical for-each loops in Java.
Fixes [COMMONSRDF-12](https://issues.apache.org/jira/browse/COMMONSRDF-12)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/stain/incubator-commonsrdf COMMONSRDF-12-graph-iterable
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-commonsrdf/pull/8.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #8
----
commit 1dcfafb9ddfb47153b1bf52989513518597c6017
Author: Stian Soiland-Reyes <st...@apache.org>
Date: 2015-04-10T09:39:10Z
COMMONSRDF-12 Graph implements Iterable interface
..with a default method that simply calls getTriples().iterator
This is mainly to be useful for classical for-each loops in Java.
----
> Graph to be Iterable
> --------------------
>
> Key: COMMONSRDF-12
> URL: https://issues.apache.org/jira/browse/COMMONSRDF-12
> Project: Apache Commons RDF
> Issue Type: New Feature
> Reporter: Stian Soiland-Reyes
> Assignee: Stian Soiland-Reyes
>
> A Graph is a collection of triples, yet it does not support the Iterable interface, and thus can't be used in a classic for-each loop like:
> {code}
> for (Triple t : graph) {
> System.out.println(t);
> }
> {code}
> instead you are forced to use .getTriples() and either .sequential().forEach, or the awkward casting with ::iterator
> http://stackoverflow.com/questions/20129762/why-does-streamt-not-implement-iterablet
> Note that Stream is not Iterable, as it can only be iterated over once.. (I often find my self adding a function like iterable() to work around such cases).
> My proposal is simply to add the interface Iterable and have a default implementation that calls getTriples().iterator().
> It could be that there are other solutions that also work with the filtered getTriples() - e.g. some kind of Collector that is iterable?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)