{"action":"created","comment":{"url":"https://api.github.com/repos/fusonic/linq/pulls/comments/43880342","id":43880342,"diff_hunk":"@@ -0,0 +1,98 @@\n+<?php\n+\n+/*\n+ * This file is part of Fusonic-linq.\n+ * https://github.com/fusonic/fusonic-linq\n+ *\n+ * (c) Fusonic GmbH\n+ *\n+ * For the full copyright and license information, please view the LICENSE\n+ * file that was distributed with this source code.\n+ */\n+\n+namespace Fusonic\\Linq\\Iterator;\n+\n+use Countable;\n+use Fusonic\\Linq\\Linq;\n+use Iterator;\n+\n+/**\n+ * Iterates over an iterator, returning Linq objects of the given chunk size.\n+ */\n+class ChunkIterator implements Iterator, Countable\n+{\n+    /**\n+     * @var Iterator\n+     */\n+    private $iterator;\n+\n+    /**\n+     * @var int\n+     */\n+    private $i = 0;\n+\n+    /**\n+     * @var int\n+     */\n+    private $chunkSize;\n+\n+    public function __construct(Iterator $iterator, $chunkSize)\n+    {\n+        $this->iterator = $iterator;\n+        $this->chunkSize = $chunkSize;\n+    }\n+\n+    /**\n+     * @return Linq\n+     * @todo Should this chunking logic stay here? This might be better in `next()` but then `current()` should return\n+     *       the first chunk before we call `next()`. With current implementation, looping through without calling\n+     *       `current()` is inconsistent, hence the `count()` implementation.\n+     */\n+    public function current()\n+    {\n+        $chunk = [];\n+        while ($this->valid()) {\n+            $chunk[] = $this->iterator->current();\n+\n+            if (count($chunk) < $this->chunkSize) {\n+                $this->iterator->next();\n+            } else {\n+                break;\n+            }\n+        }\n+\n+        return new Linq($chunk);\n+    }\n+\n+    public function next()\n+    {\n+        $this->iterator->next();\n+        $this->i++;\n+    }\n+\n+    public function key()\n+    {\n+        return $this->i;\n+    }\n+\n+    public function valid()\n+    {\n+        return $this->iterator->valid();","path":"src/Fusonic/Linq/Iterator/ChunkIterator.php","position":80,"original_position":80,"commit_id":"1eebe80ad023d155d4d303ddcc88831da60d234f","original_commit_id":"1eebe80ad023d155d4d303ddcc88831da60d234f","user":{"login":"davidroth","id":338856,"avatar_url":"https://avatars.githubusercontent.com/u/338856?v=3","gravatar_id":"","url":"https://api.github.com/users/davidroth","html_url":"https://github.com/davidroth","followers_url":"https://api.github.com/users/davidroth/followers","following_url":"https://api.github.com/users/davidroth/following{/other_user}","gists_url":"https://api.github.com/users/davidroth/gists{/gist_id}","starred_url":"https://api.github.com/users/davidroth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidroth/subscriptions","organizations_url":"https://api.github.com/users/davidroth/orgs","repos_url":"https://api.github.com/users/davidroth/repos","events_url":"https://api.github.com/users/davidroth/events{/privacy}","received_events_url":"https://api.github.com/users/davidroth/received_events","type":"User","site_admin":false},"body":"Should return true if the current chunk ist not null.","created_at":"2015-11-04T13:36:43Z","updated_at":"2015-11-04T13:36:43Z","html_url":"https://github.com/fusonic/linq/pull/19#discussion_r43880342","pull_request_url":"https://api.github.com/repos/fusonic/linq/pulls/19","_links":{"self":{"href":"https://api.github.com/repos/fusonic/linq/pulls/comments/43880342"},"html":{"href":"https://github.com/fusonic/linq/pull/19#discussion_r43880342"},"pull_request":{"href":"https://api.github.com/repos/fusonic/linq/pulls/19"}}},"pull_request":{"url":"https://api.github.com/repos/fusonic/linq/pulls/19","id":49579271,"html_url":"https://github.com/fusonic/linq/pull/19","diff_url":"https://github.com/fusonic/linq/pull/19.diff","patch_url":"https://github.com/fusonic/linq/pull/19.patch","issue_url":"https://api.github.com/repos/fusonic/linq/issues/19","number":19,"state":"open","locked":false,"title":"Implement chunking without use of group iterator","user":{"login":"robations","id":205320,"avatar_url":"https://avatars.githubusercontent.com/u/205320?v=3","gravatar_id":"","url":"https://api.github.com/users/robations","html_url":"https://github.com/robations","followers_url":"https://api.github.com/users/robations/followers","following_url":"https://api.github.com/users/robations/following{/other_user}","gists_url":"https://api.github.com/users/robations/gists{/gist_id}","starred_url":"https://api.github.com/users/robations/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robations/subscriptions","organizations_url":"https://api.github.com/users/robations/orgs","repos_url":"https://api.github.com/users/robations/repos","events_url":"https://api.github.com/users/robations/events{/privacy}","received_events_url":"https://api.github.com/users/robations/received_events","type":"User","site_admin":false},"body":"See what you think of this. Notes on changes:\r\n\r\n- I created another iterator `ChunkIterator`, as using `yield` on its own was not quite working as anticipated.\r\n- I added tests for `ChunkIterator` and for the new chunking behaviour, all passing here.\r\n- Because `yield` isn't used, earlier PHP versions could still be supported, but here I have still bumped the version requirement to 5.5.\r\n- `ChunkIterator` seems to work okay for the purposes here, but there are some potential inconsistencies, basically a conflict between `current()` and `next()`. There's a note in the code.\r\n- I added phpunit as a dev dependency, which can then be invoked by `vendor/bin/phpunit`. For me this works better and ensures the installed phpunit is aligned with the current project.\r\n- Minor updates to docs where necessary, check out the diff.\r\n\r\nPerhaps some changes are slightly opinionated but any comments or suggestions are welcome.","created_at":"2015-11-03T16:41:28Z","updated_at":"2015-11-04T13:36:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"593487c00405b137cf048b58d78abc8356d23c03","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fusonic/linq/pulls/19/commits","review_comments_url":"https://api.github.com/repos/fusonic/linq/pulls/19/comments","review_comment_url":"https://api.github.com/repos/fusonic/linq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fusonic/linq/issues/19/comments","statuses_url":"https://api.github.com/repos/fusonic/linq/statuses/1eebe80ad023d155d4d303ddcc88831da60d234f","head":{"label":"robations:feature/chunk-without-group","ref":"feature/chunk-without-group","sha":"1eebe80ad023d155d4d303ddcc88831da60d234f","user":{"login":"robations","id":205320,"avatar_url":"https://avatars.githubusercontent.com/u/205320?v=3","gravatar_id":"","url":"https://api.github.com/users/robations","html_url":"https://github.com/robations","followers_url":"https://api.github.com/users/robations/followers","following_url":"https://api.github.com/users/robations/following{/other_user}","gists_url":"https://api.github.com/users/robations/gists{/gist_id}","starred_url":"https://api.github.com/users/robations/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robations/subscriptions","organizations_url":"https://api.github.com/users/robations/orgs","repos_url":"https://api.github.com/users/robations/repos","events_url":"https://api.github.com/users/robations/events{/privacy}","received_events_url":"https://api.github.com/users/robations/received_events","type":"User","site_admin":false},"repo":{"id":45462293,"name":"linq","full_name":"robations/linq","owner":{"login":"robations","id":205320,"avatar_url":"https://avatars.githubusercontent.com/u/205320?v=3","gravatar_id":"","url":"https://api.github.com/users/robations","html_url":"https://github.com/robations","followers_url":"https://api.github.com/users/robations/followers","following_url":"https://api.github.com/users/robations/following{/other_user}","gists_url":"https://api.github.com/users/robations/gists{/gist_id}","starred_url":"https://api.github.com/users/robations/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robations/subscriptions","organizations_url":"https://api.github.com/users/robations/orgs","repos_url":"https://api.github.com/users/robations/repos","events_url":"https://api.github.com/users/robations/events{/privacy}","received_events_url":"https://api.github.com/users/robations/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/robations/linq","description":"PHP implementation of LINQ 2 Objects","fork":true,"url":"https://api.github.com/repos/robations/linq","forks_url":"https://api.github.com/repos/robations/linq/forks","keys_url":"https://api.github.com/repos/robations/linq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/robations/linq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/robations/linq/teams","hooks_url":"https://api.github.com/repos/robations/linq/hooks","issue_events_url":"https://api.github.com/repos/robations/linq/issues/events{/number}","events_url":"https://api.github.com/repos/robations/linq/events","assignees_url":"https://api.github.com/repos/robations/linq/assignees{/user}","branches_url":"https://api.github.com/repos/robations/linq/branches{/branch}","tags_url":"https://api.github.com/repos/robations/linq/tags","blobs_url":"https://api.github.com/repos/robations/linq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/robations/linq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/robations/linq/git/refs{/sha}","trees_url":"https://api.github.com/repos/robations/linq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/robations/linq/statuses/{sha}","languages_url":"https://api.github.com/repos/robations/linq/languages","stargazers_url":"https://api.github.com/repos/robations/linq/stargazers","contributors_url":"https://api.github.com/repos/robations/linq/contributors","subscribers_url":"https://api.github.com/repos/robations/linq/subscribers","subscription_url":"https://api.github.com/repos/robations/linq/subscription","commits_url":"https://api.github.com/repos/robations/linq/commits{/sha}","git_commits_url":"https://api.github.com/repos/robations/linq/git/commits{/sha}","comments_url":"https://api.github.com/repos/robations/linq/comments{/number}","issue_comment_url":"https://api.github.com/repos/robations/linq/issues/comments{/number}","contents_url":"https://api.github.com/repos/robations/linq/contents/{+path}","compare_url":"https://api.github.com/repos/robations/linq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/robations/linq/merges","archive_url":"https://api.github.com/repos/robations/linq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/robations/linq/downloads","issues_url":"https://api.github.com/repos/robations/linq/issues{/number}","pulls_url":"https://api.github.com/repos/robations/linq/pulls{/number}","milestones_url":"https://api.github.com/repos/robations/linq/milestones{/number}","notifications_url":"https://api.github.com/repos/robations/linq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/robations/linq/labels{/name}","releases_url":"https://api.github.com/repos/robations/linq/releases{/id}","created_at":"2015-11-03T11:33:38Z","updated_at":"2015-11-03T11:33:38Z","pushed_at":"2015-11-03T16:45:56Z","git_url":"git://github.com/robations/linq.git","ssh_url":"git@github.com:robations/linq.git","clone_url":"https://github.com/robations/linq.git","svn_url":"https://github.com/robations/linq","homepage":"http://fusonic.github.io/linq/","size":539,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"fusonic:master","ref":"master","sha":"7c5a10ce09aa8b4d6924e123c2bedb3bbd81eda1","user":{"login":"fusonic","id":809603,"avatar_url":"https://avatars.githubusercontent.com/u/809603?v=3","gravatar_id":"","url":"https://api.github.com/users/fusonic","html_url":"https://github.com/fusonic","followers_url":"https://api.github.com/users/fusonic/followers","following_url":"https://api.github.com/users/fusonic/following{/other_user}","gists_url":"https://api.github.com/users/fusonic/gists{/gist_id}","starred_url":"https://api.github.com/users/fusonic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fusonic/subscriptions","organizations_url":"https://api.github.com/users/fusonic/orgs","repos_url":"https://api.github.com/users/fusonic/repos","events_url":"https://api.github.com/users/fusonic/events{/privacy}","received_events_url":"https://api.github.com/users/fusonic/received_events","type":"Organization","site_admin":false},"repo":{"id":10693784,"name":"linq","full_name":"fusonic/linq","owner":{"login":"fusonic","id":809603,"avatar_url":"https://avatars.githubusercontent.com/u/809603?v=3","gravatar_id":"","url":"https://api.github.com/users/fusonic","html_url":"https://github.com/fusonic","followers_url":"https://api.github.com/users/fusonic/followers","following_url":"https://api.github.com/users/fusonic/following{/other_user}","gists_url":"https://api.github.com/users/fusonic/gists{/gist_id}","starred_url":"https://api.github.com/users/fusonic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fusonic/subscriptions","organizations_url":"https://api.github.com/users/fusonic/orgs","repos_url":"https://api.github.com/users/fusonic/repos","events_url":"https://api.github.com/users/fusonic/events{/privacy}","received_events_url":"https://api.github.com/users/fusonic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fusonic/linq","description":"PHP implementation of LINQ 2 Objects","fork":false,"url":"https://api.github.com/repos/fusonic/linq","forks_url":"https://api.github.com/repos/fusonic/linq/forks","keys_url":"https://api.github.com/repos/fusonic/linq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fusonic/linq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fusonic/linq/teams","hooks_url":"https://api.github.com/repos/fusonic/linq/hooks","issue_events_url":"https://api.github.com/repos/fusonic/linq/issues/events{/number}","events_url":"https://api.github.com/repos/fusonic/linq/events","assignees_url":"https://api.github.com/repos/fusonic/linq/assignees{/user}","branches_url":"https://api.github.com/repos/fusonic/linq/branches{/branch}","tags_url":"https://api.github.com/repos/fusonic/linq/tags","blobs_url":"https://api.github.com/repos/fusonic/linq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fusonic/linq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fusonic/linq/git/refs{/sha}","trees_url":"https://api.github.com/repos/fusonic/linq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fusonic/linq/statuses/{sha}","languages_url":"https://api.github.com/repos/fusonic/linq/languages","stargazers_url":"https://api.github.com/repos/fusonic/linq/stargazers","contributors_url":"https://api.github.com/repos/fusonic/linq/contributors","subscribers_url":"https://api.github.com/repos/fusonic/linq/subscribers","subscription_url":"https://api.github.com/repos/fusonic/linq/subscription","commits_url":"https://api.github.com/repos/fusonic/linq/commits{/sha}","git_commits_url":"https://api.github.com/repos/fusonic/linq/git/commits{/sha}","comments_url":"https://api.github.com/repos/fusonic/linq/comments{/number}","issue_comment_url":"https://api.github.com/repos/fusonic/linq/issues/comments{/number}","contents_url":"https://api.github.com/repos/fusonic/linq/contents/{+path}","compare_url":"https://api.github.com/repos/fusonic/linq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fusonic/linq/merges","archive_url":"https://api.github.com/repos/fusonic/linq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fusonic/linq/downloads","issues_url":"https://api.github.com/repos/fusonic/linq/issues{/number}","pulls_url":"https://api.github.com/repos/fusonic/linq/pulls{/number}","milestones_url":"https://api.github.com/repos/fusonic/linq/milestones{/number}","notifications_url":"https://api.github.com/repos/fusonic/linq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fusonic/linq/labels{/name}","releases_url":"https://api.github.com/repos/fusonic/linq/releases{/id}","created_at":"2013-06-14T17:06:03Z","updated_at":"2015-10-23T10:41:52Z","pushed_at":"2015-11-03T16:45:56Z","git_url":"git://github.com/fusonic/linq.git","ssh_url":"git@github.com:fusonic/linq.git","clone_url":"https://github.com/fusonic/linq.git","svn_url":"https://github.com/fusonic/linq","homepage":"http://fusonic.github.io/linq/","size":921,"stargazers_count":21,"watchers_count":21,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":5,"mirror_url":null,"open_issues_count":7,"forks":5,"open_issues":7,"watchers":21,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fusonic/linq/pulls/19"},"html":{"href":"https://github.com/fusonic/linq/pull/19"},"issue":{"href":"https://api.github.com/repos/fusonic/linq/issues/19"},"comments":{"href":"https://api.github.com/repos/fusonic/linq/issues/19/comments"},"review_comments":{"href":"https://api.github.com/repos/fusonic/linq/pulls/19/comments"},"review_comment":{"href":"https://api.github.com/repos/fusonic/linq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fusonic/linq/pulls/19/commits"},"statuses":{"href":"https://api.github.com/repos/fusonic/linq/statuses/1eebe80ad023d155d4d303ddcc88831da60d234f"}}}}