{"action":"created","comment":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/39045998","id":39045998,"diff_hunk":"@@ -1565,3 +1565,184 @@ unittest\n                 2, \"two\",\n                 ));\n }\n+\n+// TODO Why does this return $(D false) when $(D T) is a $(D string) or array: isImplicitlyConvertible!(bool, T);\n+enum implicitlyConvertsToBool(T) = isImplicitlyConvertible!(bool, T) || isArray!T;\n+import std.typetuple : allSatisfy;\n+\n+/** Returns: First Argument (element of $(D a)) whose implicit conversion to\n+    $(D bool) is $(D true.\n+\n+    Similar to behaviour of or operator in dynamic languages such as Lisp's (or\n+    a...) and Python's a or ....\n+\n+    TODO: Is inout Conversion!T the correct return value?\n+\n+    NOTE: Lazy parameters are currently, too restrictively, inferred by DMD to\n+    always throw eventhough they don't need to be. This makes it impossible to\n+    mark $(D either) as $(D nothrow). Issue at\n+    https://issues.dlang.org/show_bug.cgi?id=12647\n+*/\n+CommonType!Ts either(Ts...)(lazy Ts a)\n+if (a.length >= 1 &&\n+    !is(CommonType!Ts == void) &&\n+    allSatisfy!(implicitlyConvertsToBool, Ts))\n+{\n+    foreach (e; a)\n+        if (e)\n+            return e;\n+    return CommonType!Ts.init;\n+}\n+\n+/// ditto\n+auto ref either(Ts...)(ref Ts a)","path":"std/algorithm/comparison.d","position":34,"original_position":34,"commit_id":"a21d094860ac554b6efccb4ffbeab55858c15554","original_commit_id":"a21d094860ac554b6efccb4ffbeab55858c15554","user":{"login":"andralex","id":566679,"avatar_url":"https://avatars.githubusercontent.com/u/566679?v=3","gravatar_id":"","url":"https://api.github.com/users/andralex","html_url":"https://github.com/andralex","followers_url":"https://api.github.com/users/andralex/followers","following_url":"https://api.github.com/users/andralex/following{/other_user}","gists_url":"https://api.github.com/users/andralex/gists{/gist_id}","starred_url":"https://api.github.com/users/andralex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andralex/subscriptions","organizations_url":"https://api.github.com/users/andralex/orgs","repos_url":"https://api.github.com/users/andralex/repos","events_url":"https://api.github.com/users/andralex/events{/privacy}","received_events_url":"https://api.github.com/users/andralex/received_events","type":"User","site_admin":false},"body":"I''m unclear how the two overloads interact. For example, a `ref` may be in fact expensive to compute e.g. `a[fun()]`, but I'd agree that it's a good heuristic to assume that lvalues are generally not expensive to compute.\r\n\r\nThe question remains what happens when the two overloads conflict?","created_at":"2015-09-09T14:06:10Z","updated_at":"2015-09-09T14:06:10Z","html_url":"https://github.com/D-Programming-Language/phobos/pull/3395#discussion_r39045998","pull_request_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3395","_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/39045998"},"html":{"href":"https://github.com/D-Programming-Language/phobos/pull/3395#discussion_r39045998"},"pull_request":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3395"}}},"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3395","id":37137342,"html_url":"https://github.com/D-Programming-Language/phobos/pull/3395","diff_url":"https://github.com/D-Programming-Language/phobos/pull/3395.diff","patch_url":"https://github.com/D-Programming-Language/phobos/pull/3395.patch","issue_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3395","number":3395,"state":"open","locked":false,"title":"Add new algorithms: either(), every() and tryAll()","user":{"login":"nordlow","id":829407,"avatar_url":"https://avatars.githubusercontent.com/u/829407?v=3","gravatar_id":"","url":"https://api.github.com/users/nordlow","html_url":"https://github.com/nordlow","followers_url":"https://api.github.com/users/nordlow/followers","following_url":"https://api.github.com/users/nordlow/following{/other_user}","gists_url":"https://api.github.com/users/nordlow/gists{/gist_id}","starred_url":"https://api.github.com/users/nordlow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nordlow/subscriptions","organizations_url":"https://api.github.com/users/nordlow/orgs","repos_url":"https://api.github.com/users/nordlow/repos","events_url":"https://api.github.com/users/nordlow/events{/privacy}","received_events_url":"https://api.github.com/users/nordlow/received_events","type":"User","site_admin":false},"body":"Thanks to D's lazy parameters, these three functions simplify pattern matching:\r\n\r\n- `either()` similar to Python/Lisp's `or`. Same as D's `any` but returns first parameter value which implicitly convert to true, or last argument otherwise. I guess `any` could be modified but that would cause breakage on its return type.\r\n- `every()` similar to Python/Lisp's `and`. Same as D's `all` but returns last parameter value upon success, `CommonType.init` otherwise. I guess `all` could be modified but that would cause breakage on its return type.\r\n- `tryAll()` used to implement backtracking in parsers.\r\n\r\nI've found real use of these in various parsing contexts.\r\n\r\nI'm very open to changing the namings if you feel they are misguiding.\r\n\r\nNote that these functions currently cannot be `nothrow` because of issue    https://issues.dlang.org/show_bug.cgi?id=12647","created_at":"2015-06-08T09:54:45Z","updated_at":"2015-09-09T14:06:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"093dc94c1b3822bfed8fea9cf88883d32e2d4714","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3395/commits","review_comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3395/comments","review_comment_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments{/number}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3395/comments","statuses_url":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/a21d094860ac554b6efccb4ffbeab55858c15554","head":{"label":"nordlow:either-and-every","ref":"either-and-every","sha":"a21d094860ac554b6efccb4ffbeab55858c15554","user":{"login":"nordlow","id":829407,"avatar_url":"https://avatars.githubusercontent.com/u/829407?v=3","gravatar_id":"","url":"https://api.github.com/users/nordlow","html_url":"https://github.com/nordlow","followers_url":"https://api.github.com/users/nordlow/followers","following_url":"https://api.github.com/users/nordlow/following{/other_user}","gists_url":"https://api.github.com/users/nordlow/gists{/gist_id}","starred_url":"https://api.github.com/users/nordlow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nordlow/subscriptions","organizations_url":"https://api.github.com/users/nordlow/orgs","repos_url":"https://api.github.com/users/nordlow/repos","events_url":"https://api.github.com/users/nordlow/events{/privacy}","received_events_url":"https://api.github.com/users/nordlow/received_events","type":"User","site_admin":false},"repo":{"id":17300435,"name":"phobos","full_name":"nordlow/phobos","owner":{"login":"nordlow","id":829407,"avatar_url":"https://avatars.githubusercontent.com/u/829407?v=3","gravatar_id":"","url":"https://api.github.com/users/nordlow","html_url":"https://github.com/nordlow","followers_url":"https://api.github.com/users/nordlow/followers","following_url":"https://api.github.com/users/nordlow/following{/other_user}","gists_url":"https://api.github.com/users/nordlow/gists{/gist_id}","starred_url":"https://api.github.com/users/nordlow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nordlow/subscriptions","organizations_url":"https://api.github.com/users/nordlow/orgs","repos_url":"https://api.github.com/users/nordlow/repos","events_url":"https://api.github.com/users/nordlow/events{/privacy}","received_events_url":"https://api.github.com/users/nordlow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nordlow/phobos","description":"The standard library of the D programming language","fork":true,"url":"https://api.github.com/repos/nordlow/phobos","forks_url":"https://api.github.com/repos/nordlow/phobos/forks","keys_url":"https://api.github.com/repos/nordlow/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nordlow/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nordlow/phobos/teams","hooks_url":"https://api.github.com/repos/nordlow/phobos/hooks","issue_events_url":"https://api.github.com/repos/nordlow/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/nordlow/phobos/events","assignees_url":"https://api.github.com/repos/nordlow/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/nordlow/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/nordlow/phobos/tags","blobs_url":"https://api.github.com/repos/nordlow/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nordlow/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nordlow/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/nordlow/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nordlow/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/nordlow/phobos/languages","stargazers_url":"https://api.github.com/repos/nordlow/phobos/stargazers","contributors_url":"https://api.github.com/repos/nordlow/phobos/contributors","subscribers_url":"https://api.github.com/repos/nordlow/phobos/subscribers","subscription_url":"https://api.github.com/repos/nordlow/phobos/subscription","commits_url":"https://api.github.com/repos/nordlow/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/nordlow/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/nordlow/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/nordlow/phobos/issues/comments{/number}","contents_url":"https://api.github.com/repos/nordlow/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/nordlow/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nordlow/phobos/merges","archive_url":"https://api.github.com/repos/nordlow/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nordlow/phobos/downloads","issues_url":"https://api.github.com/repos/nordlow/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/nordlow/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/nordlow/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/nordlow/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nordlow/phobos/labels{/name}","releases_url":"https://api.github.com/repos/nordlow/phobos/releases{/id}","created_at":"2014-02-28T21:33:26Z","updated_at":"2014-09-02T20:20:43Z","pushed_at":"2015-09-09T10:48:11Z","git_url":"git://github.com/nordlow/phobos.git","ssh_url":"git@github.com:nordlow/phobos.git","clone_url":"https://github.com/nordlow/phobos.git","svn_url":"https://github.com/nordlow/phobos","homepage":"dlang.org/phobos","size":45009,"stargazers_count":1,"watchers_count":1,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"D-Programming-Language:master","ref":"master","sha":"531d986c6f19762f2ddca326519298d43b0c2c8e","user":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"repo":{"id":1257084,"name":"phobos","full_name":"D-Programming-Language/phobos","owner":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/D-Programming-Language/phobos","description":"The standard library of the D programming language","fork":false,"url":"https://api.github.com/repos/D-Programming-Language/phobos","forks_url":"https://api.github.com/repos/D-Programming-Language/phobos/forks","keys_url":"https://api.github.com/repos/D-Programming-Language/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/D-Programming-Language/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/D-Programming-Language/phobos/teams","hooks_url":"https://api.github.com/repos/D-Programming-Language/phobos/hooks","issue_events_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/D-Programming-Language/phobos/events","assignees_url":"https://api.github.com/repos/D-Programming-Language/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/D-Programming-Language/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/D-Programming-Language/phobos/tags","blobs_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/D-Programming-Language/phobos/languages","stargazers_url":"https://api.github.com/repos/D-Programming-Language/phobos/stargazers","contributors_url":"https://api.github.com/repos/D-Programming-Language/phobos/contributors","subscribers_url":"https://api.github.com/repos/D-Programming-Language/phobos/subscribers","subscription_url":"https://api.github.com/repos/D-Programming-Language/phobos/subscription","commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/comments{/number}","contents_url":"https://api.github.com/repos/D-Programming-Language/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/D-Programming-Language/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/D-Programming-Language/phobos/merges","archive_url":"https://api.github.com/repos/D-Programming-Language/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/D-Programming-Language/phobos/downloads","issues_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/D-Programming-Language/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/D-Programming-Language/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/D-Programming-Language/phobos/labels{/name}","releases_url":"https://api.github.com/repos/D-Programming-Language/phobos/releases{/id}","created_at":"2011-01-15T07:00:06Z","updated_at":"2015-09-08T01:51:59Z","pushed_at":"2015-09-09T12:12:31Z","git_url":"git://github.com/D-Programming-Language/phobos.git","ssh_url":"git@github.com:D-Programming-Language/phobos.git","clone_url":"https://github.com/D-Programming-Language/phobos.git","svn_url":"https://github.com/D-Programming-Language/phobos","homepage":"dlang.org/phobos","size":91233,"stargazers_count":624,"watchers_count":624,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":424,"mirror_url":null,"open_issues_count":77,"forks":424,"open_issues":77,"watchers":624,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3395"},"html":{"href":"https://github.com/D-Programming-Language/phobos/pull/3395"},"issue":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3395"},"comments":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3395/comments"},"review_comments":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3395/comments"},"review_comment":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3395/commits"},"statuses":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/a21d094860ac554b6efccb4ffbeab55858c15554"}}}}