{"action":"created","comment":{"url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/comments/105765038","pull_request_review_id":26660209,"id":105765038,"diff_hunk":"@@ -0,0 +1,87 @@\n+﻿#region License and Terms\n+// MoreLINQ - Extensions to LINQ to Objects\n+// Copyright (c) 2017 Leandro F. Vieira (leandromoh). All rights reserved.\n+// \n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+// \n+//     http://www.apache.org/licenses/LICENSE-2.0\n+// \n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+#endregion\n+\n+namespace MoreLinq\n+{\n+    using System;\n+    using System.Collections.Generic;\n+\n+    static partial class MoreEnumerable\n+    {\n+        /// <summary>\n+        /// Returns a sequence generated by applying a state to the generator function, \n+        /// and from its result, determines if the sequence should have a next element and its value,\n+        /// and the next state in the recursive call.\n+        /// </summary>\n+        /// <typeparam name=\"TState\">Type of state elements.</typeparam>\n+        /// <typeparam name=\"T\">Type of the elements generated by the generator function.</typeparam>\n+        /// <typeparam name=\"TResult\">The type of the elements of the result sequence.</typeparam>\n+        /// <param name=\"state\">The initial state.</param>\n+        /// <param name=\"generator\">\n+        /// Function that takes a state and produces an object containing all \n+        /// necessary data for the other functions (predicate, stateSelector, resultSelector).\n+        /// </param>\n+        /// <param name=\"predicate\">\n+        /// Function to determine if the unfolding should continue based on the current input.\n+        /// </param>\n+        /// <param name=\"stateSelector\">\n+        /// Function to select the state from the current input.\n+        /// </param>\n+        /// <param name=\"resultSelector\">\n+        /// Function to select the result from the current input.\n+        /// </param>\n+        /// <returns>A sequence containing the results generated by the resultSelector function.</returns>\n+        /// <remarks>\n+        /// This operator uses deferred execution and streams its results.\n+        /// </remarks>\n+\n+        public static IEnumerable<TResult> Unfold<TState, T, TResult>(\n+            TState state,\n+            Func<TState, T> generator,\n+            Func<T, bool> predicate,\n+            Func<T, TState> stateSelector,\n+            Func<T, TResult> resultSelector)\n+        {\n+            if (generator == null) throw new ArgumentNullException(nameof(generator));\n+            if (predicate == null) throw new ArgumentNullException(nameof(predicate));\n+            if (stateSelector == null) throw new ArgumentNullException(nameof(stateSelector));\n+            if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));\n+\n+            return UnfoldImpl(state, generator, predicate, stateSelector, resultSelector);\n+        }\n+\n+\n+        private static IEnumerable<TResult> UnfoldImpl<TState, T, TResult>(\n+            TState state,\n+            Func<TState, T> generator,\n+            Func<T, bool> predicate,\n+            Func<T, TState> stateSelector,\n+            Func<T, TResult> resultSelector)\n+        {\n+            while (true)\n+            {\n+                var step = generator(state);\n+\n+                if (!predicate(step))\n+                    yield break;\n+\n+                yield return resultSelector(step);\n+                state = stateSelector(step);","path":"MoreLinq/UnFold.cs","position":83,"original_position":83,"commit_id":"5d8d49d5cb0dac9b68f3bd980e43e9068a53a26b","original_commit_id":"5d8d49d5cb0dac9b68f3bd980e43e9068a53a26b","user":{"login":"fsateler","id":1322013,"avatar_url":"https://avatars1.githubusercontent.com/u/1322013?v=3","gravatar_id":"","url":"https://api.github.com/users/fsateler","html_url":"https://github.com/fsateler","followers_url":"https://api.github.com/users/fsateler/followers","following_url":"https://api.github.com/users/fsateler/following{/other_user}","gists_url":"https://api.github.com/users/fsateler/gists{/gist_id}","starred_url":"https://api.github.com/users/fsateler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fsateler/subscriptions","organizations_url":"https://api.github.com/users/fsateler/orgs","repos_url":"https://api.github.com/users/fsateler/repos","events_url":"https://api.github.com/users/fsateler/events{/privacy}","received_events_url":"https://api.github.com/users/fsateler/received_events","type":"User","site_admin":false},"body":"While coming up with an example for the overloads where one function is an identity, I realized I am confused a bit by the type distinction between `state` and `step`. Given that `state` is only used to calculate the next `step`, what do we gain by having a `stateSelector` at all? Or in other words, what is the advantage of the current version over:\r\n\r\n```csharp\r\nprivate static IEnumerable<TResult> UnfoldImpl<TState, TResult>(\r\n    TState state,\r\n    Func<TState, TState> generator,\r\n    Func<TState, bool> predicate,\r\n    Func<TState, TResult> resultSelector)\r\n{\r\n    while (true)\r\n    {\r\n        var step = generator(state);\r\n\r\n        if (!predicate(step))\r\n            yield break;\r\n\r\n        yield return resultSelector(step);\r\n        state = step;\r\n    }\r\n}\r\n```\r\n\r\nWhat am I missing?","created_at":"2017-03-13T20:36:54Z","updated_at":"2017-03-13T20:36:54Z","html_url":"https://github.com/morelinq/MoreLINQ/pull/260#discussion_r105765038","pull_request_url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/260","_links":{"self":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/comments/105765038"},"html":{"href":"https://github.com/morelinq/MoreLINQ/pull/260#discussion_r105765038"},"pull_request":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/260"}}},"pull_request":{"url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/260","id":109400823,"html_url":"https://github.com/morelinq/MoreLINQ/pull/260","diff_url":"https://github.com/morelinq/MoreLINQ/pull/260.diff","patch_url":"https://github.com/morelinq/MoreLINQ/pull/260.patch","issue_url":"https://api.github.com/repos/morelinq/MoreLINQ/issues/260","number":260,"state":"open","locked":false,"title":"Implemented Unfold (Issue 246) ","user":{"login":"leandromoh","id":11452028,"avatar_url":"https://avatars2.githubusercontent.com/u/11452028?v=3","gravatar_id":"","url":"https://api.github.com/users/leandromoh","html_url":"https://github.com/leandromoh","followers_url":"https://api.github.com/users/leandromoh/followers","following_url":"https://api.github.com/users/leandromoh/following{/other_user}","gists_url":"https://api.github.com/users/leandromoh/gists{/gist_id}","starred_url":"https://api.github.com/users/leandromoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leandromoh/subscriptions","organizations_url":"https://api.github.com/users/leandromoh/orgs","repos_url":"https://api.github.com/users/leandromoh/repos","events_url":"https://api.github.com/users/leandromoh/events{/privacy}","received_events_url":"https://api.github.com/users/leandromoh/received_events","type":"User","site_admin":false},"body":"Implemented Unfold method (#246).","created_at":"2017-03-07T03:40:46Z","updated_at":"2017-03-13T20:36:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1421d28c6e81cad7e8b82067941b203a1b870042","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/260/commits","review_comments_url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/260/comments","review_comment_url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/comments{/number}","comments_url":"https://api.github.com/repos/morelinq/MoreLINQ/issues/260/comments","statuses_url":"https://api.github.com/repos/morelinq/MoreLINQ/statuses/5d8d49d5cb0dac9b68f3bd980e43e9068a53a26b","head":{"label":"leandromoh:unfold","ref":"unfold","sha":"5d8d49d5cb0dac9b68f3bd980e43e9068a53a26b","user":{"login":"leandromoh","id":11452028,"avatar_url":"https://avatars2.githubusercontent.com/u/11452028?v=3","gravatar_id":"","url":"https://api.github.com/users/leandromoh","html_url":"https://github.com/leandromoh","followers_url":"https://api.github.com/users/leandromoh/followers","following_url":"https://api.github.com/users/leandromoh/following{/other_user}","gists_url":"https://api.github.com/users/leandromoh/gists{/gist_id}","starred_url":"https://api.github.com/users/leandromoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leandromoh/subscriptions","organizations_url":"https://api.github.com/users/leandromoh/orgs","repos_url":"https://api.github.com/users/leandromoh/repos","events_url":"https://api.github.com/users/leandromoh/events{/privacy}","received_events_url":"https://api.github.com/users/leandromoh/received_events","type":"User","site_admin":false},"repo":{"id":68558536,"name":"MoreLINQ","full_name":"leandromoh/MoreLINQ","owner":{"login":"leandromoh","id":11452028,"avatar_url":"https://avatars2.githubusercontent.com/u/11452028?v=3","gravatar_id":"","url":"https://api.github.com/users/leandromoh","html_url":"https://github.com/leandromoh","followers_url":"https://api.github.com/users/leandromoh/followers","following_url":"https://api.github.com/users/leandromoh/following{/other_user}","gists_url":"https://api.github.com/users/leandromoh/gists{/gist_id}","starred_url":"https://api.github.com/users/leandromoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leandromoh/subscriptions","organizations_url":"https://api.github.com/users/leandromoh/orgs","repos_url":"https://api.github.com/users/leandromoh/repos","events_url":"https://api.github.com/users/leandromoh/events{/privacy}","received_events_url":"https://api.github.com/users/leandromoh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/leandromoh/MoreLINQ","description":"Extensions to LINQ to Objects","fork":true,"url":"https://api.github.com/repos/leandromoh/MoreLINQ","forks_url":"https://api.github.com/repos/leandromoh/MoreLINQ/forks","keys_url":"https://api.github.com/repos/leandromoh/MoreLINQ/keys{/key_id}","collaborators_url":"https://api.github.com/repos/leandromoh/MoreLINQ/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/leandromoh/MoreLINQ/teams","hooks_url":"https://api.github.com/repos/leandromoh/MoreLINQ/hooks","issue_events_url":"https://api.github.com/repos/leandromoh/MoreLINQ/issues/events{/number}","events_url":"https://api.github.com/repos/leandromoh/MoreLINQ/events","assignees_url":"https://api.github.com/repos/leandromoh/MoreLINQ/assignees{/user}","branches_url":"https://api.github.com/repos/leandromoh/MoreLINQ/branches{/branch}","tags_url":"https://api.github.com/repos/leandromoh/MoreLINQ/tags","blobs_url":"https://api.github.com/repos/leandromoh/MoreLINQ/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/leandromoh/MoreLINQ/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/leandromoh/MoreLINQ/git/refs{/sha}","trees_url":"https://api.github.com/repos/leandromoh/MoreLINQ/git/trees{/sha}","statuses_url":"https://api.github.com/repos/leandromoh/MoreLINQ/statuses/{sha}","languages_url":"https://api.github.com/repos/leandromoh/MoreLINQ/languages","stargazers_url":"https://api.github.com/repos/leandromoh/MoreLINQ/stargazers","contributors_url":"https://api.github.com/repos/leandromoh/MoreLINQ/contributors","subscribers_url":"https://api.github.com/repos/leandromoh/MoreLINQ/subscribers","subscription_url":"https://api.github.com/repos/leandromoh/MoreLINQ/subscription","commits_url":"https://api.github.com/repos/leandromoh/MoreLINQ/commits{/sha}","git_commits_url":"https://api.github.com/repos/leandromoh/MoreLINQ/git/commits{/sha}","comments_url":"https://api.github.com/repos/leandromoh/MoreLINQ/comments{/number}","issue_comment_url":"https://api.github.com/repos/leandromoh/MoreLINQ/issues/comments{/number}","contents_url":"https://api.github.com/repos/leandromoh/MoreLINQ/contents/{+path}","compare_url":"https://api.github.com/repos/leandromoh/MoreLINQ/compare/{base}...{head}","merges_url":"https://api.github.com/repos/leandromoh/MoreLINQ/merges","archive_url":"https://api.github.com/repos/leandromoh/MoreLINQ/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/leandromoh/MoreLINQ/downloads","issues_url":"https://api.github.com/repos/leandromoh/MoreLINQ/issues{/number}","pulls_url":"https://api.github.com/repos/leandromoh/MoreLINQ/pulls{/number}","milestones_url":"https://api.github.com/repos/leandromoh/MoreLINQ/milestones{/number}","notifications_url":"https://api.github.com/repos/leandromoh/MoreLINQ/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/leandromoh/MoreLINQ/labels{/name}","releases_url":"https://api.github.com/repos/leandromoh/MoreLINQ/releases{/id}","deployments_url":"https://api.github.com/repos/leandromoh/MoreLINQ/deployments","created_at":"2016-09-19T01:34:37Z","updated_at":"2016-09-19T01:34:38Z","pushed_at":"2017-03-11T20:09:22Z","git_url":"git://github.com/leandromoh/MoreLINQ.git","ssh_url":"git@github.com:leandromoh/MoreLINQ.git","clone_url":"https://github.com/leandromoh/MoreLINQ.git","svn_url":"https://github.com/leandromoh/MoreLINQ","homepage":"https://morelinq.github.io/","size":2141,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"morelinq:master","ref":"master","sha":"dbad4803bedfef69f6a27cd897d0a4b2a66ce491","user":{"login":"morelinq","id":13901851,"avatar_url":"https://avatars1.githubusercontent.com/u/13901851?v=3","gravatar_id":"","url":"https://api.github.com/users/morelinq","html_url":"https://github.com/morelinq","followers_url":"https://api.github.com/users/morelinq/followers","following_url":"https://api.github.com/users/morelinq/following{/other_user}","gists_url":"https://api.github.com/users/morelinq/gists{/gist_id}","starred_url":"https://api.github.com/users/morelinq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/morelinq/subscriptions","organizations_url":"https://api.github.com/users/morelinq/orgs","repos_url":"https://api.github.com/users/morelinq/repos","events_url":"https://api.github.com/users/morelinq/events{/privacy}","received_events_url":"https://api.github.com/users/morelinq/received_events","type":"Organization","site_admin":false},"repo":{"id":41150635,"name":"MoreLINQ","full_name":"morelinq/MoreLINQ","owner":{"login":"morelinq","id":13901851,"avatar_url":"https://avatars1.githubusercontent.com/u/13901851?v=3","gravatar_id":"","url":"https://api.github.com/users/morelinq","html_url":"https://github.com/morelinq","followers_url":"https://api.github.com/users/morelinq/followers","following_url":"https://api.github.com/users/morelinq/following{/other_user}","gists_url":"https://api.github.com/users/morelinq/gists{/gist_id}","starred_url":"https://api.github.com/users/morelinq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/morelinq/subscriptions","organizations_url":"https://api.github.com/users/morelinq/orgs","repos_url":"https://api.github.com/users/morelinq/repos","events_url":"https://api.github.com/users/morelinq/events{/privacy}","received_events_url":"https://api.github.com/users/morelinq/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/morelinq/MoreLINQ","description":"Extensions to LINQ to Objects","fork":false,"url":"https://api.github.com/repos/morelinq/MoreLINQ","forks_url":"https://api.github.com/repos/morelinq/MoreLINQ/forks","keys_url":"https://api.github.com/repos/morelinq/MoreLINQ/keys{/key_id}","collaborators_url":"https://api.github.com/repos/morelinq/MoreLINQ/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/morelinq/MoreLINQ/teams","hooks_url":"https://api.github.com/repos/morelinq/MoreLINQ/hooks","issue_events_url":"https://api.github.com/repos/morelinq/MoreLINQ/issues/events{/number}","events_url":"https://api.github.com/repos/morelinq/MoreLINQ/events","assignees_url":"https://api.github.com/repos/morelinq/MoreLINQ/assignees{/user}","branches_url":"https://api.github.com/repos/morelinq/MoreLINQ/branches{/branch}","tags_url":"https://api.github.com/repos/morelinq/MoreLINQ/tags","blobs_url":"https://api.github.com/repos/morelinq/MoreLINQ/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/morelinq/MoreLINQ/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/morelinq/MoreLINQ/git/refs{/sha}","trees_url":"https://api.github.com/repos/morelinq/MoreLINQ/git/trees{/sha}","statuses_url":"https://api.github.com/repos/morelinq/MoreLINQ/statuses/{sha}","languages_url":"https://api.github.com/repos/morelinq/MoreLINQ/languages","stargazers_url":"https://api.github.com/repos/morelinq/MoreLINQ/stargazers","contributors_url":"https://api.github.com/repos/morelinq/MoreLINQ/contributors","subscribers_url":"https://api.github.com/repos/morelinq/MoreLINQ/subscribers","subscription_url":"https://api.github.com/repos/morelinq/MoreLINQ/subscription","commits_url":"https://api.github.com/repos/morelinq/MoreLINQ/commits{/sha}","git_commits_url":"https://api.github.com/repos/morelinq/MoreLINQ/git/commits{/sha}","comments_url":"https://api.github.com/repos/morelinq/MoreLINQ/comments{/number}","issue_comment_url":"https://api.github.com/repos/morelinq/MoreLINQ/issues/comments{/number}","contents_url":"https://api.github.com/repos/morelinq/MoreLINQ/contents/{+path}","compare_url":"https://api.github.com/repos/morelinq/MoreLINQ/compare/{base}...{head}","merges_url":"https://api.github.com/repos/morelinq/MoreLINQ/merges","archive_url":"https://api.github.com/repos/morelinq/MoreLINQ/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/morelinq/MoreLINQ/downloads","issues_url":"https://api.github.com/repos/morelinq/MoreLINQ/issues{/number}","pulls_url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls{/number}","milestones_url":"https://api.github.com/repos/morelinq/MoreLINQ/milestones{/number}","notifications_url":"https://api.github.com/repos/morelinq/MoreLINQ/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/morelinq/MoreLINQ/labels{/name}","releases_url":"https://api.github.com/repos/morelinq/MoreLINQ/releases{/id}","deployments_url":"https://api.github.com/repos/morelinq/MoreLINQ/deployments","created_at":"2015-08-21T10:39:10Z","updated_at":"2017-03-11T22:38:05Z","pushed_at":"2017-03-11T20:09:23Z","git_url":"git://github.com/morelinq/MoreLINQ.git","ssh_url":"git@github.com:morelinq/MoreLINQ.git","clone_url":"https://github.com/morelinq/MoreLINQ.git","svn_url":"https://github.com/morelinq/MoreLINQ","homepage":"https://morelinq.github.io/","size":2169,"stargazers_count":489,"watchers_count":489,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":79,"mirror_url":null,"open_issues_count":48,"forks":79,"open_issues":48,"watchers":489,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/260"},"html":{"href":"https://github.com/morelinq/MoreLINQ/pull/260"},"issue":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/issues/260"},"comments":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/issues/260/comments"},"review_comments":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/260/comments"},"review_comment":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/260/commits"},"statuses":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/statuses/5d8d49d5cb0dac9b68f3bd980e43e9068a53a26b"}}}}
{"actor":{"display_login":"fsateler"}}