{"action":"created","comment":{"url":"https://api.github.com/repos/functionaljava/functionaljava/pulls/comments/23033753","id":23033753,"diff_hunk":"@@ -1840,4 +1839,31 @@ private void copy() {\n     @Override public String toString() {\n         return Show.listShow( Show.<A>anyShow() ).show( this ).foldLeft((s, c) -> s + c, \"\" );\n     }\n+\n+    /**\n+     * True if the list is a singleton.  Faster than checking <code>length() == 1</code> for any\n+     * list with <code>length() > 1</code>.\n+     */\n+\tpublic boolean isSingle() {\n+\t\treturn isNotEmpty() && tail().isEmpty();\n+\t}\n+\n+\t/**\n+\t * Compare elements of this list to the elements in the other list.  If one\n+\t * list is a prefix of the other, the shorter list is considered to be less\n+\t * than the longer list.\n+\t *\n+\t * @param ord Ordering to use for comparison\n+\t * @param other Other list to compare with\n+\t * @return An Ordering result\n+\t */\n+\tpublic Ordering compare(Ord<A> ord, List<A> other) {\n+\t\tOrdering cmp = Ord.booleanOrd.compare(isEmpty(), other.isEmpty());\n+\t\tif(isEmpty() || cmp != Ordering.EQ)\n+\t\t\treturn cmp;\n+\t\tcmp = ord.compare(head(), other.head());\n+\t\tif(cmp != Ordering.EQ)\n+\t\t\treturn cmp;\n+\t\treturn tail().compare(ord, other.tail());\n+\t}","path":"core/src/main/java/fj/data/List.java","position":38,"original_position":38,"commit_id":"37ef7652cc3099efd6bed7746bf5c769c55d390f","original_commit_id":"37ef7652cc3099efd6bed7746bf5c769c55d390f","user":{"login":"dobesv","id":327833,"avatar_url":"https://avatars.githubusercontent.com/u/327833?v=3","gravatar_id":"","url":"https://api.github.com/users/dobesv","html_url":"https://github.com/dobesv","followers_url":"https://api.github.com/users/dobesv/followers","following_url":"https://api.github.com/users/dobesv/following{/other_user}","gists_url":"https://api.github.com/users/dobesv/gists{/gist_id}","starred_url":"https://api.github.com/users/dobesv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobesv/subscriptions","organizations_url":"https://api.github.com/users/dobesv/orgs","repos_url":"https://api.github.com/users/dobesv/repos","events_url":"https://api.github.com/users/dobesv/events{/privacy}","received_events_url":"https://api.github.com/users/dobesv/received_events","type":"User","site_admin":false},"body":"Ah I hadn't thought of using Ord.listOrd . Should I just eliminate the\r\ncompare method?\r\n On Jan 15, 2015 3:27 AM, \"Mark Perry\" <notifications@github.com> wrote:\r\n\r\n> In core/src/main/java/fj/data/List.java\r\n> <https://github.com/functionaljava/functionaljava/pull/82#discussion-diff-23003879>\r\n> :\r\n>\r\n> > +\t * list is a prefix of the other, the shorter list is considered to be less\r\n> > +\t * than the longer list.\r\n> > +\t *\r\n> > +\t * @param ord Ordering to use for comparison\r\n> > +\t * @param other Other list to compare with\r\n> > +\t * @return An Ordering result\r\n> > +\t */\r\n> > +\tpublic Ordering compare(Ord<A> ord, List<A> other) {\r\n> > +\t\tOrdering cmp = Ord.booleanOrd.compare(isEmpty(), other.isEmpty());\r\n> > +\t\tif(isEmpty() || cmp != Ordering.EQ)\r\n> > +\t\t\treturn cmp;\r\n> > +\t\tcmp = ord.compare(head(), other.head());\r\n> > +\t\tif(cmp != Ordering.EQ)\r\n> > +\t\t\treturn cmp;\r\n> > +\t\treturn tail().compare(ord, other.tail());\r\n> > +\t}\r\n>\r\n> You may not be aware, but there are static fields on Ord for many of the\r\n> common classes\r\n> Reusing this implementation means the method body is:\r\n>\r\n> return Ord.listOrd(ord).compare(this, other);\r\n>\r\n> Probably best just to reuse (most of) the javadoc from Ord.listOrd.\r\n>\r\n> —\r\n> Reply to this email directly or view it on GitHub\r\n> <https://github.com/functionaljava/functionaljava/pull/82/files#r23003879>\r\n> .\r\n>","created_at":"2015-01-15T18:59:45Z","updated_at":"2015-01-15T18:59:45Z","html_url":"https://github.com/functionaljava/functionaljava/pull/82#discussion_r23033753","pull_request_url":"https://api.github.com/repos/functionaljava/functionaljava/pulls/82","_links":{"self":{"href":"https://api.github.com/repos/functionaljava/functionaljava/pulls/comments/23033753"},"html":{"href":"https://github.com/functionaljava/functionaljava/pull/82#discussion_r23033753"},"pull_request":{"href":"https://api.github.com/repos/functionaljava/functionaljava/pulls/82"}}},"pull_request":{"url":"https://api.github.com/repos/functionaljava/functionaljava/pulls/82","id":27411291,"html_url":"https://github.com/functionaljava/functionaljava/pull/82","diff_url":"https://github.com/functionaljava/functionaljava/pull/82.diff","patch_url":"https://github.com/functionaljava/functionaljava/pull/82.patch","issue_url":"https://api.github.com/repos/functionaljava/functionaljava/issues/82","number":82,"state":"open","locked":false,"title":"Add compare() and isSingle utility methods to List.","user":{"login":"dobesv","id":327833,"avatar_url":"https://avatars.githubusercontent.com/u/327833?v=3","gravatar_id":"","url":"https://api.github.com/users/dobesv","html_url":"https://github.com/dobesv","followers_url":"https://api.github.com/users/dobesv/followers","following_url":"https://api.github.com/users/dobesv/following{/other_user}","gists_url":"https://api.github.com/users/dobesv/gists{/gist_id}","starred_url":"https://api.github.com/users/dobesv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobesv/subscriptions","organizations_url":"https://api.github.com/users/dobesv/orgs","repos_url":"https://api.github.com/users/dobesv/repos","events_url":"https://api.github.com/users/dobesv/events{/privacy}","received_events_url":"https://api.github.com/users/dobesv/received_events","type":"User","site_admin":false},"body":"These are a couple of methods I find useful.  One to check if a list has only a single element, and another to compare two lists using an Ord.","created_at":"2015-01-15T07:53:13Z","updated_at":"2015-01-15T18:59:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0604a827410ec50a30f572414609b29eb189dd1f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/functionaljava/functionaljava/pulls/82/commits","review_comments_url":"https://api.github.com/repos/functionaljava/functionaljava/pulls/82/comments","review_comment_url":"https://api.github.com/repos/functionaljava/functionaljava/pulls/comments/{number}","comments_url":"https://api.github.com/repos/functionaljava/functionaljava/issues/82/comments","statuses_url":"https://api.github.com/repos/functionaljava/functionaljava/statuses/37ef7652cc3099efd6bed7746bf5c769c55d390f","head":{"label":"dobesv:list-compare-issingle","ref":"list-compare-issingle","sha":"37ef7652cc3099efd6bed7746bf5c769c55d390f","user":{"login":"dobesv","id":327833,"avatar_url":"https://avatars.githubusercontent.com/u/327833?v=3","gravatar_id":"","url":"https://api.github.com/users/dobesv","html_url":"https://github.com/dobesv","followers_url":"https://api.github.com/users/dobesv/followers","following_url":"https://api.github.com/users/dobesv/following{/other_user}","gists_url":"https://api.github.com/users/dobesv/gists{/gist_id}","starred_url":"https://api.github.com/users/dobesv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobesv/subscriptions","organizations_url":"https://api.github.com/users/dobesv/orgs","repos_url":"https://api.github.com/users/dobesv/repos","events_url":"https://api.github.com/users/dobesv/events{/privacy}","received_events_url":"https://api.github.com/users/dobesv/received_events","type":"User","site_admin":false},"repo":{"id":13713978,"name":"functionaljava","full_name":"dobesv/functionaljava","owner":{"login":"dobesv","id":327833,"avatar_url":"https://avatars.githubusercontent.com/u/327833?v=3","gravatar_id":"","url":"https://api.github.com/users/dobesv","html_url":"https://github.com/dobesv","followers_url":"https://api.github.com/users/dobesv/followers","following_url":"https://api.github.com/users/dobesv/following{/other_user}","gists_url":"https://api.github.com/users/dobesv/gists{/gist_id}","starred_url":"https://api.github.com/users/dobesv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobesv/subscriptions","organizations_url":"https://api.github.com/users/dobesv/orgs","repos_url":"https://api.github.com/users/dobesv/repos","events_url":"https://api.github.com/users/dobesv/events{/privacy}","received_events_url":"https://api.github.com/users/dobesv/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dobesv/functionaljava","description":"Functional Java","fork":true,"url":"https://api.github.com/repos/dobesv/functionaljava","forks_url":"https://api.github.com/repos/dobesv/functionaljava/forks","keys_url":"https://api.github.com/repos/dobesv/functionaljava/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dobesv/functionaljava/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dobesv/functionaljava/teams","hooks_url":"https://api.github.com/repos/dobesv/functionaljava/hooks","issue_events_url":"https://api.github.com/repos/dobesv/functionaljava/issues/events{/number}","events_url":"https://api.github.com/repos/dobesv/functionaljava/events","assignees_url":"https://api.github.com/repos/dobesv/functionaljava/assignees{/user}","branches_url":"https://api.github.com/repos/dobesv/functionaljava/branches{/branch}","tags_url":"https://api.github.com/repos/dobesv/functionaljava/tags","blobs_url":"https://api.github.com/repos/dobesv/functionaljava/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dobesv/functionaljava/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dobesv/functionaljava/git/refs{/sha}","trees_url":"https://api.github.com/repos/dobesv/functionaljava/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dobesv/functionaljava/statuses/{sha}","languages_url":"https://api.github.com/repos/dobesv/functionaljava/languages","stargazers_url":"https://api.github.com/repos/dobesv/functionaljava/stargazers","contributors_url":"https://api.github.com/repos/dobesv/functionaljava/contributors","subscribers_url":"https://api.github.com/repos/dobesv/functionaljava/subscribers","subscription_url":"https://api.github.com/repos/dobesv/functionaljava/subscription","commits_url":"https://api.github.com/repos/dobesv/functionaljava/commits{/sha}","git_commits_url":"https://api.github.com/repos/dobesv/functionaljava/git/commits{/sha}","comments_url":"https://api.github.com/repos/dobesv/functionaljava/comments{/number}","issue_comment_url":"https://api.github.com/repos/dobesv/functionaljava/issues/comments/{number}","contents_url":"https://api.github.com/repos/dobesv/functionaljava/contents/{+path}","compare_url":"https://api.github.com/repos/dobesv/functionaljava/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dobesv/functionaljava/merges","archive_url":"https://api.github.com/repos/dobesv/functionaljava/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dobesv/functionaljava/downloads","issues_url":"https://api.github.com/repos/dobesv/functionaljava/issues{/number}","pulls_url":"https://api.github.com/repos/dobesv/functionaljava/pulls{/number}","milestones_url":"https://api.github.com/repos/dobesv/functionaljava/milestones{/number}","notifications_url":"https://api.github.com/repos/dobesv/functionaljava/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dobesv/functionaljava/labels{/name}","releases_url":"https://api.github.com/repos/dobesv/functionaljava/releases{/id}","created_at":"2013-10-20T05:12:14Z","updated_at":"2015-01-05T06:49:21Z","pushed_at":"2015-01-15T08:29:01Z","git_url":"git://github.com/dobesv/functionaljava.git","ssh_url":"git@github.com:dobesv/functionaljava.git","clone_url":"https://github.com/dobesv/functionaljava.git","svn_url":"https://github.com/dobesv/functionaljava","homepage":"http://functionaljava.org/","size":1999,"stargazers_count":0,"watchers_count":0,"language":"Java","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":"functionaljava:master","ref":"master","sha":"7f8330bbb9aad9ada5e2eabc2f6db1a0d207b6c5","user":{"login":"functionaljava","id":458836,"avatar_url":"https://avatars.githubusercontent.com/u/458836?v=3","gravatar_id":"","url":"https://api.github.com/users/functionaljava","html_url":"https://github.com/functionaljava","followers_url":"https://api.github.com/users/functionaljava/followers","following_url":"https://api.github.com/users/functionaljava/following{/other_user}","gists_url":"https://api.github.com/users/functionaljava/gists{/gist_id}","starred_url":"https://api.github.com/users/functionaljava/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/functionaljava/subscriptions","organizations_url":"https://api.github.com/users/functionaljava/orgs","repos_url":"https://api.github.com/users/functionaljava/repos","events_url":"https://api.github.com/users/functionaljava/events{/privacy}","received_events_url":"https://api.github.com/users/functionaljava/received_events","type":"Organization","site_admin":false},"repo":{"id":1033614,"name":"functionaljava","full_name":"functionaljava/functionaljava","owner":{"login":"functionaljava","id":458836,"avatar_url":"https://avatars.githubusercontent.com/u/458836?v=3","gravatar_id":"","url":"https://api.github.com/users/functionaljava","html_url":"https://github.com/functionaljava","followers_url":"https://api.github.com/users/functionaljava/followers","following_url":"https://api.github.com/users/functionaljava/following{/other_user}","gists_url":"https://api.github.com/users/functionaljava/gists{/gist_id}","starred_url":"https://api.github.com/users/functionaljava/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/functionaljava/subscriptions","organizations_url":"https://api.github.com/users/functionaljava/orgs","repos_url":"https://api.github.com/users/functionaljava/repos","events_url":"https://api.github.com/users/functionaljava/events{/privacy}","received_events_url":"https://api.github.com/users/functionaljava/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/functionaljava/functionaljava","description":"Functional programming in Java","fork":false,"url":"https://api.github.com/repos/functionaljava/functionaljava","forks_url":"https://api.github.com/repos/functionaljava/functionaljava/forks","keys_url":"https://api.github.com/repos/functionaljava/functionaljava/keys{/key_id}","collaborators_url":"https://api.github.com/repos/functionaljava/functionaljava/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/functionaljava/functionaljava/teams","hooks_url":"https://api.github.com/repos/functionaljava/functionaljava/hooks","issue_events_url":"https://api.github.com/repos/functionaljava/functionaljava/issues/events{/number}","events_url":"https://api.github.com/repos/functionaljava/functionaljava/events","assignees_url":"https://api.github.com/repos/functionaljava/functionaljava/assignees{/user}","branches_url":"https://api.github.com/repos/functionaljava/functionaljava/branches{/branch}","tags_url":"https://api.github.com/repos/functionaljava/functionaljava/tags","blobs_url":"https://api.github.com/repos/functionaljava/functionaljava/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/functionaljava/functionaljava/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/functionaljava/functionaljava/git/refs{/sha}","trees_url":"https://api.github.com/repos/functionaljava/functionaljava/git/trees{/sha}","statuses_url":"https://api.github.com/repos/functionaljava/functionaljava/statuses/{sha}","languages_url":"https://api.github.com/repos/functionaljava/functionaljava/languages","stargazers_url":"https://api.github.com/repos/functionaljava/functionaljava/stargazers","contributors_url":"https://api.github.com/repos/functionaljava/functionaljava/contributors","subscribers_url":"https://api.github.com/repos/functionaljava/functionaljava/subscribers","subscription_url":"https://api.github.com/repos/functionaljava/functionaljava/subscription","commits_url":"https://api.github.com/repos/functionaljava/functionaljava/commits{/sha}","git_commits_url":"https://api.github.com/repos/functionaljava/functionaljava/git/commits{/sha}","comments_url":"https://api.github.com/repos/functionaljava/functionaljava/comments{/number}","issue_comment_url":"https://api.github.com/repos/functionaljava/functionaljava/issues/comments/{number}","contents_url":"https://api.github.com/repos/functionaljava/functionaljava/contents/{+path}","compare_url":"https://api.github.com/repos/functionaljava/functionaljava/compare/{base}...{head}","merges_url":"https://api.github.com/repos/functionaljava/functionaljava/merges","archive_url":"https://api.github.com/repos/functionaljava/functionaljava/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/functionaljava/functionaljava/downloads","issues_url":"https://api.github.com/repos/functionaljava/functionaljava/issues{/number}","pulls_url":"https://api.github.com/repos/functionaljava/functionaljava/pulls{/number}","milestones_url":"https://api.github.com/repos/functionaljava/functionaljava/milestones{/number}","notifications_url":"https://api.github.com/repos/functionaljava/functionaljava/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/functionaljava/functionaljava/labels{/name}","releases_url":"https://api.github.com/repos/functionaljava/functionaljava/releases{/id}","created_at":"2010-10-29T00:19:26Z","updated_at":"2015-01-15T04:16:58Z","pushed_at":"2015-01-15T04:16:58Z","git_url":"git://github.com/functionaljava/functionaljava.git","ssh_url":"git@github.com:functionaljava/functionaljava.git","clone_url":"https://github.com/functionaljava/functionaljava.git","svn_url":"https://github.com/functionaljava/functionaljava","homepage":"www.functionaljava.org","size":3616,"stargazers_count":383,"watchers_count":383,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":75,"mirror_url":null,"open_issues_count":10,"forks":75,"open_issues":10,"watchers":383,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/functionaljava/functionaljava/pulls/82"},"html":{"href":"https://github.com/functionaljava/functionaljava/pull/82"},"issue":{"href":"https://api.github.com/repos/functionaljava/functionaljava/issues/82"},"comments":{"href":"https://api.github.com/repos/functionaljava/functionaljava/issues/82/comments"},"review_comments":{"href":"https://api.github.com/repos/functionaljava/functionaljava/pulls/82/comments"},"review_comment":{"href":"https://api.github.com/repos/functionaljava/functionaljava/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/functionaljava/functionaljava/pulls/82/commits"},"statuses":{"href":"https://api.github.com/repos/functionaljava/functionaljava/statuses/37ef7652cc3099efd6bed7746bf5c769c55d390f"}}}}