{"action":"created","comment":{"url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/comments/167876821","pull_request_review_id":96155611,"id":167876821,"diff_hunk":"@@ -81,29 +81,74 @@ static partial class MoreEnumerable\n         // >\n         // > - https://en.wikipedia.org/wiki/Maxima_and_minima\n \n-        static TSource ExtremumBy<TSource, TKey>(IEnumerable<TSource> source,\n+        static IEnumerable<TSource> ExtremaBy<TSource, TKey>(IEnumerable<TSource> source,\n             Func<TSource, TKey> selector, Func<TKey, TKey, int> comparer)\n         {\n-            using (var sourceIterator = source.GetEnumerator())\n+            return new LazyList<TSource>(new Lazy<List<TSource>>(() =>\n             {\n-                if (!sourceIterator.MoveNext())\n-                    throw new InvalidOperationException(\"Sequence contains no elements\");\n-\n-                var extremum = sourceIterator.Current;\n-                var key = selector(extremum);\n-                while (sourceIterator.MoveNext())\n+                using (var e = source.GetEnumerator())\n                 {\n-                    var candidate = sourceIterator.Current;\n-                    var candidateProjected = selector(candidate);\n-                    if (comparer(candidateProjected, key) > 0)\n+                    if (!e.MoveNext())\n+                        return new List<TSource>();\n+\n+                    var extrema = new List<TSource> { e.Current };\n+                    var extremaKey = selector(e.Current);\n+\n+                    while (e.MoveNext())\n                     {\n-                        extremum = candidate;\n-                        key = candidateProjected;\n+                        var item = e.Current;\n+                        var key = selector(item);\n+                        var comparison = comparer(key, extremaKey);\n+                        if (comparison > 0)\n+                        {\n+                            extrema = new List<TSource> { item };","path":"MoreLinq/MaxBy.cs","position":112,"original_position":112,"commit_id":"0b14a714245265bc923cbdcb839279b032d63559","original_commit_id":"0b14a714245265bc923cbdcb839279b032d63559","user":{"login":"fsateler","id":1322013,"avatar_url":"https://avatars2.githubusercontent.com/u/1322013?v=4","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":"Is there a reason for not using `extrema.Clear()` + `extrema.Add(item)` ? Using this could save some allocations and GC pressure, at the cost of potentially keeping more memory allocated than strictly necessary (ie, if there are many equal keys that appear before the true maximal key).","created_at":"2018-02-13T14:18:21Z","updated_at":"2018-02-13T14:19:47Z","html_url":"https://github.com/morelinq/MoreLINQ/pull/369#discussion_r167876821","pull_request_url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/369","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/comments/167876821"},"html":{"href":"https://github.com/morelinq/MoreLINQ/pull/369#discussion_r167876821"},"pull_request":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/369"}}},"pull_request":{"url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/369","id":165052086,"html_url":"https://github.com/morelinq/MoreLINQ/pull/369","diff_url":"https://github.com/morelinq/MoreLINQ/pull/369.diff","patch_url":"https://github.com/morelinq/MoreLINQ/pull/369.patch","issue_url":"https://api.github.com/repos/morelinq/MoreLINQ/issues/369","number":369,"state":"open","locked":false,"title":"Change MaxBy/MinBy to return all extrema elements (#328)","user":{"login":"atifaziz","id":20511,"avatar_url":"https://avatars2.githubusercontent.com/u/20511?v=4","gravatar_id":"","url":"https://api.github.com/users/atifaziz","html_url":"https://github.com/atifaziz","followers_url":"https://api.github.com/users/atifaziz/followers","following_url":"https://api.github.com/users/atifaziz/following{/other_user}","gists_url":"https://api.github.com/users/atifaziz/gists{/gist_id}","starred_url":"https://api.github.com/users/atifaziz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atifaziz/subscriptions","organizations_url":"https://api.github.com/users/atifaziz/orgs","repos_url":"https://api.github.com/users/atifaziz/repos","events_url":"https://api.github.com/users/atifaziz/events{/privacy}","received_events_url":"https://api.github.com/users/atifaziz/received_events","type":"User","site_admin":false},"body":"This PR addresses #328.","created_at":"2018-01-25T08:03:08Z","updated_at":"2018-02-13T14:19:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bd2e83cc081c0368dc9de9552b640128414628a8","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/369/commits","review_comments_url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/369/comments","review_comment_url":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/comments{/number}","comments_url":"https://api.github.com/repos/morelinq/MoreLINQ/issues/369/comments","statuses_url":"https://api.github.com/repos/morelinq/MoreLINQ/statuses/0b14a714245265bc923cbdcb839279b032d63559","head":{"label":"atifaziz:extrema-by","ref":"extrema-by","sha":"0b14a714245265bc923cbdcb839279b032d63559","user":{"login":"atifaziz","id":20511,"avatar_url":"https://avatars2.githubusercontent.com/u/20511?v=4","gravatar_id":"","url":"https://api.github.com/users/atifaziz","html_url":"https://github.com/atifaziz","followers_url":"https://api.github.com/users/atifaziz/followers","following_url":"https://api.github.com/users/atifaziz/following{/other_user}","gists_url":"https://api.github.com/users/atifaziz/gists{/gist_id}","starred_url":"https://api.github.com/users/atifaziz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atifaziz/subscriptions","organizations_url":"https://api.github.com/users/atifaziz/orgs","repos_url":"https://api.github.com/users/atifaziz/repos","events_url":"https://api.github.com/users/atifaziz/events{/privacy}","received_events_url":"https://api.github.com/users/atifaziz/received_events","type":"User","site_admin":false},"repo":{"id":69985233,"name":"MoreLINQ","full_name":"atifaziz/MoreLINQ","owner":{"login":"atifaziz","id":20511,"avatar_url":"https://avatars2.githubusercontent.com/u/20511?v=4","gravatar_id":"","url":"https://api.github.com/users/atifaziz","html_url":"https://github.com/atifaziz","followers_url":"https://api.github.com/users/atifaziz/followers","following_url":"https://api.github.com/users/atifaziz/following{/other_user}","gists_url":"https://api.github.com/users/atifaziz/gists{/gist_id}","starred_url":"https://api.github.com/users/atifaziz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atifaziz/subscriptions","organizations_url":"https://api.github.com/users/atifaziz/orgs","repos_url":"https://api.github.com/users/atifaziz/repos","events_url":"https://api.github.com/users/atifaziz/events{/privacy}","received_events_url":"https://api.github.com/users/atifaziz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/atifaziz/MoreLINQ","description":"Extensions to LINQ to Objects","fork":true,"url":"https://api.github.com/repos/atifaziz/MoreLINQ","forks_url":"https://api.github.com/repos/atifaziz/MoreLINQ/forks","keys_url":"https://api.github.com/repos/atifaziz/MoreLINQ/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atifaziz/MoreLINQ/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atifaziz/MoreLINQ/teams","hooks_url":"https://api.github.com/repos/atifaziz/MoreLINQ/hooks","issue_events_url":"https://api.github.com/repos/atifaziz/MoreLINQ/issues/events{/number}","events_url":"https://api.github.com/repos/atifaziz/MoreLINQ/events","assignees_url":"https://api.github.com/repos/atifaziz/MoreLINQ/assignees{/user}","branches_url":"https://api.github.com/repos/atifaziz/MoreLINQ/branches{/branch}","tags_url":"https://api.github.com/repos/atifaziz/MoreLINQ/tags","blobs_url":"https://api.github.com/repos/atifaziz/MoreLINQ/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atifaziz/MoreLINQ/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atifaziz/MoreLINQ/git/refs{/sha}","trees_url":"https://api.github.com/repos/atifaziz/MoreLINQ/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atifaziz/MoreLINQ/statuses/{sha}","languages_url":"https://api.github.com/repos/atifaziz/MoreLINQ/languages","stargazers_url":"https://api.github.com/repos/atifaziz/MoreLINQ/stargazers","contributors_url":"https://api.github.com/repos/atifaziz/MoreLINQ/contributors","subscribers_url":"https://api.github.com/repos/atifaziz/MoreLINQ/subscribers","subscription_url":"https://api.github.com/repos/atifaziz/MoreLINQ/subscription","commits_url":"https://api.github.com/repos/atifaziz/MoreLINQ/commits{/sha}","git_commits_url":"https://api.github.com/repos/atifaziz/MoreLINQ/git/commits{/sha}","comments_url":"https://api.github.com/repos/atifaziz/MoreLINQ/comments{/number}","issue_comment_url":"https://api.github.com/repos/atifaziz/MoreLINQ/issues/comments{/number}","contents_url":"https://api.github.com/repos/atifaziz/MoreLINQ/contents/{+path}","compare_url":"https://api.github.com/repos/atifaziz/MoreLINQ/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atifaziz/MoreLINQ/merges","archive_url":"https://api.github.com/repos/atifaziz/MoreLINQ/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atifaziz/MoreLINQ/downloads","issues_url":"https://api.github.com/repos/atifaziz/MoreLINQ/issues{/number}","pulls_url":"https://api.github.com/repos/atifaziz/MoreLINQ/pulls{/number}","milestones_url":"https://api.github.com/repos/atifaziz/MoreLINQ/milestones{/number}","notifications_url":"https://api.github.com/repos/atifaziz/MoreLINQ/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atifaziz/MoreLINQ/labels{/name}","releases_url":"https://api.github.com/repos/atifaziz/MoreLINQ/releases{/id}","deployments_url":"https://api.github.com/repos/atifaziz/MoreLINQ/deployments","created_at":"2016-10-04T16:42:15Z","updated_at":"2018-01-24T18:16:58Z","pushed_at":"2018-02-11T16:44:37Z","git_url":"git://github.com/atifaziz/MoreLINQ.git","ssh_url":"git@github.com:atifaziz/MoreLINQ.git","clone_url":"https://github.com/atifaziz/MoreLINQ.git","svn_url":"https://github.com/atifaziz/MoreLINQ","homepage":"https://morelinq.github.io/","size":2532,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"morelinq:master","ref":"master","sha":"f6610814e7099d78f464527967c366e90574dc65","user":{"login":"morelinq","id":13901851,"avatar_url":"https://avatars2.githubusercontent.com/u/13901851?v=4","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://avatars2.githubusercontent.com/u/13901851?v=4","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":"2018-02-13T00:14:36Z","pushed_at":"2018-02-11T18:22:27Z","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":2472,"stargazers_count":848,"watchers_count":848,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":134,"mirror_url":null,"archived":false,"open_issues_count":57,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":134,"open_issues":57,"watchers":848,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/369"},"html":{"href":"https://github.com/morelinq/MoreLINQ/pull/369"},"issue":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/issues/369"},"comments":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/issues/369/comments"},"review_comments":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/369/comments"},"review_comment":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/pulls/369/commits"},"statuses":{"href":"https://api.github.com/repos/morelinq/MoreLINQ/statuses/0b14a714245265bc923cbdcb839279b032d63559"}},"author_association":"OWNER"}}
{"actor":{"display_login":"fsateler"}}