{"action":"created","comment":{"url":"https://api.github.com/repos/folktale/data.task/pulls/comments/58971651","id":58971651,"diff_hunk":"@@ -128,10 +128,46 @@ Task.prototype.chain = function _chain(f) {\n  * @summary @Task[α, (β → γ)] => Task[α, β] → Task[α, γ]\n  */\n \n-Task.prototype.ap = function _ap(f2) {\n-  return this.chain(function(f) {\n-    return f2.map(f);\n-  });\n+Task.prototype.ap = function _ap(that) {\n+  var forkThis = this.fork;\n+  var forkThat = that.fork;\n+  var cleanupThis = this.cleanup;\n+  var cleanupThat = that.cleanup;\n+\n+  function cleanupBoth(state) {\n+    cleanupThis(state[0]);\n+    cleanupThat(state[1]);\n+  }\n+\n+  return new Task(function(reject, resolve) {\n+    var func, funcLoaded = false;\n+    var val, valLoaded = false;\n+    var allState;\n+\n+    var thisState = forkThis(reject, guard(function(x) {\n+      funcLoaded = true;\n+      func = x;\n+    }));\n+\n+    var thatState = forkThat(reject, guard(function(x) {\n+      valLoaded = true;\n+      val = x;\n+    }));\n+\n+    function guard(setter) {\n+      return function(x) {\n+        setter(x);","path":"lib/task.js","position":36,"original_position":36,"commit_id":"0c7f4ad931f02d7850c3ea681f14121a0002573b","original_commit_id":"0c7f4ad931f02d7850c3ea681f14121a0002573b","user":{"login":"robotlolita","id":406477,"avatar_url":"https://avatars.githubusercontent.com/u/406477?v=3","gravatar_id":"","url":"https://api.github.com/users/robotlolita","html_url":"https://github.com/robotlolita","followers_url":"https://api.github.com/users/robotlolita/followers","following_url":"https://api.github.com/users/robotlolita/following{/other_user}","gists_url":"https://api.github.com/users/robotlolita/gists{/gist_id}","starred_url":"https://api.github.com/users/robotlolita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robotlolita/subscriptions","organizations_url":"https://api.github.com/users/robotlolita/orgs","repos_url":"https://api.github.com/users/robotlolita/repos","events_url":"https://api.github.com/users/robotlolita/events{/privacy}","received_events_url":"https://api.github.com/users/robotlolita/received_events","type":"User","site_admin":false},"body":"Unsure if we should put something like `if (rejected) return` here. It does guard against bad things, but OTOH if something is calling both the `resolved` and `rejected` callback we've got bigger problems?","created_at":"2016-04-08T01:54:01Z","updated_at":"2016-04-08T01:54:01Z","html_url":"https://github.com/folktale/data.task/pull/33#discussion_r58971651","pull_request_url":"https://api.github.com/repos/folktale/data.task/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/folktale/data.task/pulls/comments/58971651"},"html":{"href":"https://github.com/folktale/data.task/pull/33#discussion_r58971651"},"pull_request":{"href":"https://api.github.com/repos/folktale/data.task/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/folktale/data.task/pulls/33","id":64488833,"html_url":"https://github.com/folktale/data.task/pull/33","diff_url":"https://github.com/folktale/data.task/pull/33.diff","patch_url":"https://github.com/folktale/data.task/pull/33.patch","issue_url":"https://api.github.com/repos/folktale/data.task/issues/33","number":33,"state":"open","locked":false,"title":"Rewrote `ap` to be parallel instead of using sequential `chain`","user":{"login":"safareli","id":1932383,"avatar_url":"https://avatars.githubusercontent.com/u/1932383?v=3","gravatar_id":"","url":"https://api.github.com/users/safareli","html_url":"https://github.com/safareli","followers_url":"https://api.github.com/users/safareli/followers","following_url":"https://api.github.com/users/safareli/following{/other_user}","gists_url":"https://api.github.com/users/safareli/gists{/gist_id}","starred_url":"https://api.github.com/users/safareli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/safareli/subscriptions","organizations_url":"https://api.github.com/users/safareli/orgs","repos_url":"https://api.github.com/users/safareli/repos","events_url":"https://api.github.com/users/safareli/events{/privacy}","received_events_url":"https://api.github.com/users/safareli/received_events","type":"User","site_admin":false},"body":"If you have Array of Tasks and want transform it into Task of Array using traverse or sequence, tasks will be forked sequentially instead of parallel.\r\nThe reason is that `ap` is implemented using sequential `chain` method. Here it is rewritten to be parallel.","created_at":"2016-03-29T15:55:28Z","updated_at":"2016-04-08T01:54:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"db2a3b28a55d9bf31f239977dc11d30f47f2b0c7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/folktale/data.task/pulls/33/commits","review_comments_url":"https://api.github.com/repos/folktale/data.task/pulls/33/comments","review_comment_url":"https://api.github.com/repos/folktale/data.task/pulls/comments{/number}","comments_url":"https://api.github.com/repos/folktale/data.task/issues/33/comments","statuses_url":"https://api.github.com/repos/folktale/data.task/statuses/0c7f4ad931f02d7850c3ea681f14121a0002573b","head":{"label":"safareli:patch-1","ref":"patch-1","sha":"0c7f4ad931f02d7850c3ea681f14121a0002573b","user":{"login":"safareli","id":1932383,"avatar_url":"https://avatars.githubusercontent.com/u/1932383?v=3","gravatar_id":"","url":"https://api.github.com/users/safareli","html_url":"https://github.com/safareli","followers_url":"https://api.github.com/users/safareli/followers","following_url":"https://api.github.com/users/safareli/following{/other_user}","gists_url":"https://api.github.com/users/safareli/gists{/gist_id}","starred_url":"https://api.github.com/users/safareli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/safareli/subscriptions","organizations_url":"https://api.github.com/users/safareli/orgs","repos_url":"https://api.github.com/users/safareli/repos","events_url":"https://api.github.com/users/safareli/events{/privacy}","received_events_url":"https://api.github.com/users/safareli/received_events","type":"User","site_admin":false},"repo":{"id":54983479,"name":"data.task","full_name":"safareli/data.task","owner":{"login":"safareli","id":1932383,"avatar_url":"https://avatars.githubusercontent.com/u/1932383?v=3","gravatar_id":"","url":"https://api.github.com/users/safareli","html_url":"https://github.com/safareli","followers_url":"https://api.github.com/users/safareli/followers","following_url":"https://api.github.com/users/safareli/following{/other_user}","gists_url":"https://api.github.com/users/safareli/gists{/gist_id}","starred_url":"https://api.github.com/users/safareli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/safareli/subscriptions","organizations_url":"https://api.github.com/users/safareli/orgs","repos_url":"https://api.github.com/users/safareli/repos","events_url":"https://api.github.com/users/safareli/events{/privacy}","received_events_url":"https://api.github.com/users/safareli/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/safareli/data.task","description":"A monad for time-dependant values, providing explicit effects for delayed computations, latency, etc.","fork":true,"url":"https://api.github.com/repos/safareli/data.task","forks_url":"https://api.github.com/repos/safareli/data.task/forks","keys_url":"https://api.github.com/repos/safareli/data.task/keys{/key_id}","collaborators_url":"https://api.github.com/repos/safareli/data.task/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/safareli/data.task/teams","hooks_url":"https://api.github.com/repos/safareli/data.task/hooks","issue_events_url":"https://api.github.com/repos/safareli/data.task/issues/events{/number}","events_url":"https://api.github.com/repos/safareli/data.task/events","assignees_url":"https://api.github.com/repos/safareli/data.task/assignees{/user}","branches_url":"https://api.github.com/repos/safareli/data.task/branches{/branch}","tags_url":"https://api.github.com/repos/safareli/data.task/tags","blobs_url":"https://api.github.com/repos/safareli/data.task/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/safareli/data.task/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/safareli/data.task/git/refs{/sha}","trees_url":"https://api.github.com/repos/safareli/data.task/git/trees{/sha}","statuses_url":"https://api.github.com/repos/safareli/data.task/statuses/{sha}","languages_url":"https://api.github.com/repos/safareli/data.task/languages","stargazers_url":"https://api.github.com/repos/safareli/data.task/stargazers","contributors_url":"https://api.github.com/repos/safareli/data.task/contributors","subscribers_url":"https://api.github.com/repos/safareli/data.task/subscribers","subscription_url":"https://api.github.com/repos/safareli/data.task/subscription","commits_url":"https://api.github.com/repos/safareli/data.task/commits{/sha}","git_commits_url":"https://api.github.com/repos/safareli/data.task/git/commits{/sha}","comments_url":"https://api.github.com/repos/safareli/data.task/comments{/number}","issue_comment_url":"https://api.github.com/repos/safareli/data.task/issues/comments{/number}","contents_url":"https://api.github.com/repos/safareli/data.task/contents/{+path}","compare_url":"https://api.github.com/repos/safareli/data.task/compare/{base}...{head}","merges_url":"https://api.github.com/repos/safareli/data.task/merges","archive_url":"https://api.github.com/repos/safareli/data.task/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/safareli/data.task/downloads","issues_url":"https://api.github.com/repos/safareli/data.task/issues{/number}","pulls_url":"https://api.github.com/repos/safareli/data.task/pulls{/number}","milestones_url":"https://api.github.com/repos/safareli/data.task/milestones{/number}","notifications_url":"https://api.github.com/repos/safareli/data.task/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/safareli/data.task/labels{/name}","releases_url":"https://api.github.com/repos/safareli/data.task/releases{/id}","deployments_url":"https://api.github.com/repos/safareli/data.task/deployments","created_at":"2016-03-29T14:38:57Z","updated_at":"2016-03-29T14:38:57Z","pushed_at":"2016-03-29T15:55:13Z","git_url":"git://github.com/safareli/data.task.git","ssh_url":"git@github.com:safareli/data.task.git","clone_url":"https://github.com/safareli/data.task.git","svn_url":"https://github.com/safareli/data.task","homepage":"http://folktalejs.org/","size":393,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"folktale:master","ref":"master","sha":"66ee55765c9acb7f879a237495502a37e5e3355d","user":{"login":"folktale","id":6005452,"avatar_url":"https://avatars.githubusercontent.com/u/6005452?v=3","gravatar_id":"","url":"https://api.github.com/users/folktale","html_url":"https://github.com/folktale","followers_url":"https://api.github.com/users/folktale/followers","following_url":"https://api.github.com/users/folktale/following{/other_user}","gists_url":"https://api.github.com/users/folktale/gists{/gist_id}","starred_url":"https://api.github.com/users/folktale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/folktale/subscriptions","organizations_url":"https://api.github.com/users/folktale/orgs","repos_url":"https://api.github.com/users/folktale/repos","events_url":"https://api.github.com/users/folktale/events{/privacy}","received_events_url":"https://api.github.com/users/folktale/received_events","type":"Organization","site_admin":false},"repo":{"id":14670571,"name":"data.task","full_name":"folktale/data.task","owner":{"login":"folktale","id":6005452,"avatar_url":"https://avatars.githubusercontent.com/u/6005452?v=3","gravatar_id":"","url":"https://api.github.com/users/folktale","html_url":"https://github.com/folktale","followers_url":"https://api.github.com/users/folktale/followers","following_url":"https://api.github.com/users/folktale/following{/other_user}","gists_url":"https://api.github.com/users/folktale/gists{/gist_id}","starred_url":"https://api.github.com/users/folktale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/folktale/subscriptions","organizations_url":"https://api.github.com/users/folktale/orgs","repos_url":"https://api.github.com/users/folktale/repos","events_url":"https://api.github.com/users/folktale/events{/privacy}","received_events_url":"https://api.github.com/users/folktale/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/folktale/data.task","description":"A monad for time-dependant values, providing explicit effects for delayed computations, latency, etc.","fork":false,"url":"https://api.github.com/repos/folktale/data.task","forks_url":"https://api.github.com/repos/folktale/data.task/forks","keys_url":"https://api.github.com/repos/folktale/data.task/keys{/key_id}","collaborators_url":"https://api.github.com/repos/folktale/data.task/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/folktale/data.task/teams","hooks_url":"https://api.github.com/repos/folktale/data.task/hooks","issue_events_url":"https://api.github.com/repos/folktale/data.task/issues/events{/number}","events_url":"https://api.github.com/repos/folktale/data.task/events","assignees_url":"https://api.github.com/repos/folktale/data.task/assignees{/user}","branches_url":"https://api.github.com/repos/folktale/data.task/branches{/branch}","tags_url":"https://api.github.com/repos/folktale/data.task/tags","blobs_url":"https://api.github.com/repos/folktale/data.task/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/folktale/data.task/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/folktale/data.task/git/refs{/sha}","trees_url":"https://api.github.com/repos/folktale/data.task/git/trees{/sha}","statuses_url":"https://api.github.com/repos/folktale/data.task/statuses/{sha}","languages_url":"https://api.github.com/repos/folktale/data.task/languages","stargazers_url":"https://api.github.com/repos/folktale/data.task/stargazers","contributors_url":"https://api.github.com/repos/folktale/data.task/contributors","subscribers_url":"https://api.github.com/repos/folktale/data.task/subscribers","subscription_url":"https://api.github.com/repos/folktale/data.task/subscription","commits_url":"https://api.github.com/repos/folktale/data.task/commits{/sha}","git_commits_url":"https://api.github.com/repos/folktale/data.task/git/commits{/sha}","comments_url":"https://api.github.com/repos/folktale/data.task/comments{/number}","issue_comment_url":"https://api.github.com/repos/folktale/data.task/issues/comments{/number}","contents_url":"https://api.github.com/repos/folktale/data.task/contents/{+path}","compare_url":"https://api.github.com/repos/folktale/data.task/compare/{base}...{head}","merges_url":"https://api.github.com/repos/folktale/data.task/merges","archive_url":"https://api.github.com/repos/folktale/data.task/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/folktale/data.task/downloads","issues_url":"https://api.github.com/repos/folktale/data.task/issues{/number}","pulls_url":"https://api.github.com/repos/folktale/data.task/pulls{/number}","milestones_url":"https://api.github.com/repos/folktale/data.task/milestones{/number}","notifications_url":"https://api.github.com/repos/folktale/data.task/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/folktale/data.task/labels{/name}","releases_url":"https://api.github.com/repos/folktale/data.task/releases{/id}","deployments_url":"https://api.github.com/repos/folktale/data.task/deployments","created_at":"2013-11-24T22:19:48Z","updated_at":"2016-04-07T22:20:41Z","pushed_at":"2016-03-29T15:55:29Z","git_url":"git://github.com/folktale/data.task.git","ssh_url":"git@github.com:folktale/data.task.git","clone_url":"https://github.com/folktale/data.task.git","svn_url":"https://github.com/folktale/data.task","homepage":"http://folktalejs.org/","size":412,"stargazers_count":134,"watchers_count":134,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":18,"mirror_url":null,"open_issues_count":2,"forks":18,"open_issues":2,"watchers":134,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/folktale/data.task/pulls/33"},"html":{"href":"https://github.com/folktale/data.task/pull/33"},"issue":{"href":"https://api.github.com/repos/folktale/data.task/issues/33"},"comments":{"href":"https://api.github.com/repos/folktale/data.task/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/folktale/data.task/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/folktale/data.task/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/folktale/data.task/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/folktale/data.task/statuses/0c7f4ad931f02d7850c3ea681f14121a0002573b"}}}}