{"action":"created","comment":{"url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/comments/66871131","id":66871131,"diff_hunk":"@@ -0,0 +1,144 @@\n+package org.metaborg.spoofax.shell.output;\n+\n+import java.util.Objects;\n+\n+import org.metaborg.spoofax.shell.client.IResult;\n+import org.metaborg.spoofax.shell.client.IResultVisitor;\n+import org.metaborg.spoofax.shell.functions.FailableFunction;\n+\n+/**\n+ * An {@link IResult} that may be an error or a success, with in either case a wrapped result that\n+ * is respectively the representation of the error or the successful result. Our equivalent of an\n+ * \"Either\" type seen in some functional languages.\n+ *\n+ * @param <Success>\n+ *            The type of the successful {@link IResult}.\n+ * @param <Fail>\n+ *            The type of the failed {@link IResult}.\n+ */\n+public abstract class FailOrSuccessResult<Success extends IResult, Fail extends IResult>\n+    implements IResult {\n+\n+    /**\n+     * A successful result.\n+     *\n+     * @param <S>\n+     * @param <F>\n+     */\n+    private static final class Successful<S extends IResult, F extends IResult>\n+        extends FailOrSuccessResult<S, F> {\n+        private S result;\n+\n+        private Successful(S result) {\n+            this.result = result;\n+        }\n+\n+        @Override\n+        public void accept(IResultVisitor visitor) {\n+            result.accept(visitor);\n+        }\n+\n+        @Override\n+        public <NewS extends ISpoofaxResult<?>> FailOrSuccessResult<NewS, F>\n+            flatMap(FailableFunction<S, NewS, F> errorFunc) {\n+            Objects.requireNonNull(errorFunc);\n+            return errorFunc.apply(result);\n+        }\n+    }\n+\n+    /**\n+     * A failed result.\n+     *\n+     * @param <S>\n+     * @param <F>\n+     */\n+    private static final class Failed<S extends IResult, F extends IResult>\n+        extends FailOrSuccessResult<S, F> {\n+        private F result;\n+\n+        private Failed(F result) {\n+            this.result = result;\n+        }\n+\n+        @Override\n+        public void accept(IResultVisitor visitor) {\n+            result.accept(visitor);\n+        }\n+\n+        @Override\n+        public <NewS extends ISpoofaxResult<?>> FailOrSuccessResult<NewS, F>\n+            flatMap(FailableFunction<S, NewS, F> errorFunc) {\n+            Objects.requireNonNull(errorFunc);\n+            return failed(result);\n+        }\n+    }\n+\n+    /**\n+     * Create an {@link FailOrSuccessResult} that represents a successful result.\n+     *\n+     * @param successfulResult\n+     *            The successful result.\n+     * @return The {@link FailOrSuccessResult} with a wrapped result.\n+     * @param <S>\n+     *            The type of the wrapped {@link IResult}.\n+     * @param <F>\n+     *            The type of the non-existing {@link IResult} that caused an error.\n+     */\n+    public static <S extends IResult, F extends IResult> FailOrSuccessResult<S, F>\n+        successful(S successfulResult) {\n+        return new Successful<S, F>(successfulResult);\n+    }\n+\n+    /**\n+     * Create an {@link FailOrSuccessResult} that represents an unsuccessful result (error).\n+     *\n+     * @param failedResult\n+     *            The cause of the error.\n+     * @return The {@link FailOrSuccessResult} with an unsuccessful result.\n+     * @param <S>\n+     *            The type of the non-existing successful {@link ISpoofaxResult}.\n+     * @param <F>\n+     *            The type of the {@link IResult} that caused an error.\n+     */\n+    public static <S extends IResult, F extends IResult> FailOrSuccessResult<S, F>\n+        failed(F failedResult) {\n+        return new Failed<S, F>(failedResult);\n+    }\n+\n+    /**\n+     * Create an {@link FailOrSuccessResult} that, depending on whether the given\n+     * {@link ISpoofaxResult} is {@link ISpoofaxResult#valid valid}, represents either a success or\n+     * an error.\n+     *\n+     * @param result\n+     *            The cause of the error.","path":"org.metaborg.spoofax.shell.core/src/main/java/org/metaborg/spoofax/shell/output/FailOrSuccessResult.java","position":114,"original_position":114,"commit_id":"212a9c2c3cd289ef071f3477ff7f4509e926b3b0","original_commit_id":"212a9c2c3cd289ef071f3477ff7f4509e926b3b0","user":{"login":"Unia","id":1260727,"avatar_url":"https://avatars.githubusercontent.com/u/1260727?v=3","gravatar_id":"","url":"https://api.github.com/users/Unia","html_url":"https://github.com/Unia","followers_url":"https://api.github.com/users/Unia/followers","following_url":"https://api.github.com/users/Unia/following{/other_user}","gists_url":"https://api.github.com/users/Unia/gists{/gist_id}","starred_url":"https://api.github.com/users/Unia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Unia/subscriptions","organizations_url":"https://api.github.com/users/Unia/orgs","repos_url":"https://api.github.com/users/Unia/repos","events_url":"https://api.github.com/users/Unia/events{/privacy}","received_events_url":"https://api.github.com/users/Unia/received_events","type":"User","site_admin":false},"body":"Incorrect JavaDoc.","created_at":"2016-06-13T21:24:25Z","updated_at":"2016-06-13T21:24:25Z","html_url":"https://github.com/spoofax-shell/spoofax-shell/pull/30#discussion_r66871131","pull_request_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/30","_links":{"self":{"href":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/comments/66871131"},"html":{"href":"https://github.com/spoofax-shell/spoofax-shell/pull/30#discussion_r66871131"},"pull_request":{"href":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/30"}}},"pull_request":{"url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/30","id":72744191,"html_url":"https://github.com/spoofax-shell/spoofax-shell/pull/30","diff_url":"https://github.com/spoofax-shell/spoofax-shell/pull/30.diff","patch_url":"https://github.com/spoofax-shell/spoofax-shell/pull/30.patch","issue_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/issues/30","number":30,"state":"open","locked":false,"title":"[RFC] Create commands using function composition","user":{"login":"gfokkema","id":5970912,"avatar_url":"https://avatars.githubusercontent.com/u/5970912?v=3","gravatar_id":"","url":"https://api.github.com/users/gfokkema","html_url":"https://github.com/gfokkema","followers_url":"https://api.github.com/users/gfokkema/followers","following_url":"https://api.github.com/users/gfokkema/following{/other_user}","gists_url":"https://api.github.com/users/gfokkema/gists{/gist_id}","starred_url":"https://api.github.com/users/gfokkema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfokkema/subscriptions","organizations_url":"https://api.github.com/users/gfokkema/orgs","repos_url":"https://api.github.com/users/gfokkema/repos","events_url":"https://api.github.com/users/gfokkema/events{/privacy}","received_events_url":"https://api.github.com/users/gfokkema/received_events","type":"User","site_admin":false},"body":"This removes the need to create 'child commands' in for example the TransformCommand.","created_at":"2016-06-06T17:08:50Z","updated_at":"2016-06-13T21:24:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c361fcc6119c0499356e9db5d716428f2724e0db","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/30/commits","review_comments_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/30/comments","review_comment_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/comments{/number}","comments_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/issues/30/comments","statuses_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/statuses/212a9c2c3cd289ef071f3477ff7f4509e926b3b0","head":{"label":"spoofax-shell:function-comp-standalone","ref":"function-comp-standalone","sha":"212a9c2c3cd289ef071f3477ff7f4509e926b3b0","user":{"login":"spoofax-shell","id":18665559,"avatar_url":"https://avatars.githubusercontent.com/u/18665559?v=3","gravatar_id":"","url":"https://api.github.com/users/spoofax-shell","html_url":"https://github.com/spoofax-shell","followers_url":"https://api.github.com/users/spoofax-shell/followers","following_url":"https://api.github.com/users/spoofax-shell/following{/other_user}","gists_url":"https://api.github.com/users/spoofax-shell/gists{/gist_id}","starred_url":"https://api.github.com/users/spoofax-shell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spoofax-shell/subscriptions","organizations_url":"https://api.github.com/users/spoofax-shell/orgs","repos_url":"https://api.github.com/users/spoofax-shell/repos","events_url":"https://api.github.com/users/spoofax-shell/events{/privacy}","received_events_url":"https://api.github.com/users/spoofax-shell/received_events","type":"Organization","site_admin":false},"repo":{"id":57896309,"name":"spoofax-shell","full_name":"spoofax-shell/spoofax-shell","owner":{"login":"spoofax-shell","id":18665559,"avatar_url":"https://avatars.githubusercontent.com/u/18665559?v=3","gravatar_id":"","url":"https://api.github.com/users/spoofax-shell","html_url":"https://github.com/spoofax-shell","followers_url":"https://api.github.com/users/spoofax-shell/followers","following_url":"https://api.github.com/users/spoofax-shell/following{/other_user}","gists_url":"https://api.github.com/users/spoofax-shell/gists{/gist_id}","starred_url":"https://api.github.com/users/spoofax-shell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spoofax-shell/subscriptions","organizations_url":"https://api.github.com/users/spoofax-shell/orgs","repos_url":"https://api.github.com/users/spoofax-shell/repos","events_url":"https://api.github.com/users/spoofax-shell/events{/privacy}","received_events_url":"https://api.github.com/users/spoofax-shell/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spoofax-shell/spoofax-shell","description":"","fork":true,"url":"https://api.github.com/repos/spoofax-shell/spoofax-shell","forks_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/forks","keys_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/teams","hooks_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/hooks","issue_events_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/issues/events{/number}","events_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/events","assignees_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/assignees{/user}","branches_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/branches{/branch}","tags_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/tags","blobs_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/git/refs{/sha}","trees_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/statuses/{sha}","languages_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/languages","stargazers_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/stargazers","contributors_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/contributors","subscribers_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/subscribers","subscription_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/subscription","commits_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/commits{/sha}","git_commits_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/git/commits{/sha}","comments_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/comments{/number}","issue_comment_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/issues/comments{/number}","contents_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/contents/{+path}","compare_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/merges","archive_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/downloads","issues_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/issues{/number}","pulls_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls{/number}","milestones_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/milestones{/number}","notifications_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/labels{/name}","releases_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/releases{/id}","deployments_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/deployments","created_at":"2016-05-02T14:33:59Z","updated_at":"2016-05-10T18:42:24Z","pushed_at":"2016-06-13T19:14:27Z","git_url":"git://github.com/spoofax-shell/spoofax-shell.git","ssh_url":"git@github.com:spoofax-shell/spoofax-shell.git","clone_url":"https://github.com/spoofax-shell/spoofax-shell.git","svn_url":"https://github.com/spoofax-shell/spoofax-shell","homepage":null,"size":2834,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":13,"forks":0,"open_issues":13,"watchers":0,"default_branch":"master"}},"base":{"label":"spoofax-shell:master","ref":"master","sha":"ea9230cae8e30b8808c091e86b7d16e35902924f","user":{"login":"spoofax-shell","id":18665559,"avatar_url":"https://avatars.githubusercontent.com/u/18665559?v=3","gravatar_id":"","url":"https://api.github.com/users/spoofax-shell","html_url":"https://github.com/spoofax-shell","followers_url":"https://api.github.com/users/spoofax-shell/followers","following_url":"https://api.github.com/users/spoofax-shell/following{/other_user}","gists_url":"https://api.github.com/users/spoofax-shell/gists{/gist_id}","starred_url":"https://api.github.com/users/spoofax-shell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spoofax-shell/subscriptions","organizations_url":"https://api.github.com/users/spoofax-shell/orgs","repos_url":"https://api.github.com/users/spoofax-shell/repos","events_url":"https://api.github.com/users/spoofax-shell/events{/privacy}","received_events_url":"https://api.github.com/users/spoofax-shell/received_events","type":"Organization","site_admin":false},"repo":{"id":57896309,"name":"spoofax-shell","full_name":"spoofax-shell/spoofax-shell","owner":{"login":"spoofax-shell","id":18665559,"avatar_url":"https://avatars.githubusercontent.com/u/18665559?v=3","gravatar_id":"","url":"https://api.github.com/users/spoofax-shell","html_url":"https://github.com/spoofax-shell","followers_url":"https://api.github.com/users/spoofax-shell/followers","following_url":"https://api.github.com/users/spoofax-shell/following{/other_user}","gists_url":"https://api.github.com/users/spoofax-shell/gists{/gist_id}","starred_url":"https://api.github.com/users/spoofax-shell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spoofax-shell/subscriptions","organizations_url":"https://api.github.com/users/spoofax-shell/orgs","repos_url":"https://api.github.com/users/spoofax-shell/repos","events_url":"https://api.github.com/users/spoofax-shell/events{/privacy}","received_events_url":"https://api.github.com/users/spoofax-shell/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spoofax-shell/spoofax-shell","description":"","fork":true,"url":"https://api.github.com/repos/spoofax-shell/spoofax-shell","forks_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/forks","keys_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/teams","hooks_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/hooks","issue_events_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/issues/events{/number}","events_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/events","assignees_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/assignees{/user}","branches_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/branches{/branch}","tags_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/tags","blobs_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/git/refs{/sha}","trees_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/statuses/{sha}","languages_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/languages","stargazers_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/stargazers","contributors_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/contributors","subscribers_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/subscribers","subscription_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/subscription","commits_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/commits{/sha}","git_commits_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/git/commits{/sha}","comments_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/comments{/number}","issue_comment_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/issues/comments{/number}","contents_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/contents/{+path}","compare_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/merges","archive_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/downloads","issues_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/issues{/number}","pulls_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls{/number}","milestones_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/milestones{/number}","notifications_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/labels{/name}","releases_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/releases{/id}","deployments_url":"https://api.github.com/repos/spoofax-shell/spoofax-shell/deployments","created_at":"2016-05-02T14:33:59Z","updated_at":"2016-05-10T18:42:24Z","pushed_at":"2016-06-13T19:14:27Z","git_url":"git://github.com/spoofax-shell/spoofax-shell.git","ssh_url":"git@github.com:spoofax-shell/spoofax-shell.git","clone_url":"https://github.com/spoofax-shell/spoofax-shell.git","svn_url":"https://github.com/spoofax-shell/spoofax-shell","homepage":null,"size":2834,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":13,"forks":0,"open_issues":13,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/30"},"html":{"href":"https://github.com/spoofax-shell/spoofax-shell/pull/30"},"issue":{"href":"https://api.github.com/repos/spoofax-shell/spoofax-shell/issues/30"},"comments":{"href":"https://api.github.com/repos/spoofax-shell/spoofax-shell/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/spoofax-shell/spoofax-shell/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/spoofax-shell/spoofax-shell/statuses/212a9c2c3cd289ef071f3477ff7f4509e926b3b0"}}}}
{"actor":{"display_login":"Unia"}}