{"action":"created","comment":{"url":"https://api.github.com/repos/typelevel/cats/pulls/comments/108996106","pull_request_review_id":30068570,"id":108996106,"diff_hunk":"@@ -14,4 +14,90 @@ import simulacrum.typeclass\n @typeclass trait Monad[F[_]] extends FlatMap[F] with Applicative[F] {\n   override def map[A, B](fa: F[A])(f: A => B): F[B] =\n     flatMap(fa)(a => pure(f(a)))\n+\n+  /**\n+   * Execute an action repeatedly as long as the given `Boolean` expression\n+   * returns `true`. The condition is evaluated before the loop body.\n+   * Collects the results into an arbitrary `Alternative` value, such as a `Vector`.\n+   * This implementation uses append on each evaluation result,\n+   * so avoid data structures with non-constant append performance, e.g. `List`.\n+  */\n+  def whileM[G[_], A](p: F[Boolean])(body: => F[A])(implicit G: Alternative[G]): F[G[A]] = {\n+    val b = Eval.later(body)\n+    tailRecM[G[A], G[A]](G.empty)(xs => ifM(p)(\n+      ifTrue = {\n+        map(b.value) { bv =>\n+          Left(G.combineK(xs, G.pure(bv)))\n+        }\n+      },\n+      ifFalse = pure(xs.asRight[G[A]])\n+    ))\n+  }\n+\n+  /**\n+   * Execute an action repeatedly as long as the given `Boolean` expression\n+   * returns `true`. The condition is evaluated before the loop body.\n+   * Discards results.\n+   */\n+  def whileM_[A](p: F[Boolean])(body: => F[A]): F[Unit] = {\n+    val continue: Either[Unit, Unit] = Left(())\n+    val stop: F[Either[Unit, Unit]] = pure(Right(()))\n+    val b = Eval.later(body)\n+    tailRecM(())(_ => ifM(p)(\n+      ifTrue = {\n+        map(b.value)(_ => continue)\n+      },\n+      ifFalse = stop\n+    ))\n+  }\n+\n+  /**\n+   * Execute an action repeatedly until the `Boolean` condition returns `true`.\n+   * The condition is evaluated after the loop body. Collects results into an\n+   * arbitrary `Alternative` value, such as a `Vector`.\n+   * This implementation uses append on each evaluation result,\n+   * so avoid data structures with non-constant append performance, e.g. `List`.\n+   */\n+  def untilM[G[_], A](f: F[A])(cond: => F[Boolean])(implicit G: Alternative[G]): F[G[A]] = {\n+    val p = Eval.later(cond)\n+    flatMap(f)(x => map(whileM(map(p.value)(!_))(f))(xs => G.combineK(G.pure(x), xs)))\n+  }","path":"core/src/main/scala/cats/Monad.scala","position":60,"original_position":60,"commit_id":"5d173f14b14ced058d16a6eb535481ae0c5f8e0a","original_commit_id":"5d173f14b14ced058d16a6eb535481ae0c5f8e0a","user":{"login":"tpolecat","id":1200131,"avatar_url":"https://avatars3.githubusercontent.com/u/1200131?v=3","gravatar_id":"","url":"https://api.github.com/users/tpolecat","html_url":"https://github.com/tpolecat","followers_url":"https://api.github.com/users/tpolecat/followers","following_url":"https://api.github.com/users/tpolecat/following{/other_user}","gists_url":"https://api.github.com/users/tpolecat/gists{/gist_id}","starred_url":"https://api.github.com/users/tpolecat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tpolecat/subscriptions","organizations_url":"https://api.github.com/users/tpolecat/orgs","repos_url":"https://api.github.com/users/tpolecat/repos","events_url":"https://api.github.com/users/tpolecat/events{/privacy}","received_events_url":"https://api.github.com/users/tpolecat/received_events","type":"User","site_admin":false},"body":"Yeah see https://github.com/scalaz/scalaz/issues/1144 for discussion (moving my comment up).","created_at":"2017-03-30T18:03:56Z","updated_at":"2017-03-30T18:03:57Z","html_url":"https://github.com/typelevel/cats/pull/1571#discussion_r108996106","pull_request_url":"https://api.github.com/repos/typelevel/cats/pulls/1571","_links":{"self":{"href":"https://api.github.com/repos/typelevel/cats/pulls/comments/108996106"},"html":{"href":"https://github.com/typelevel/cats/pull/1571#discussion_r108996106"},"pull_request":{"href":"https://api.github.com/repos/typelevel/cats/pulls/1571"}}},"pull_request":{"url":"https://api.github.com/repos/typelevel/cats/pulls/1571","id":112479433,"html_url":"https://github.com/typelevel/cats/pull/1571","diff_url":"https://github.com/typelevel/cats/pull/1571.diff","patch_url":"https://github.com/typelevel/cats/pull/1571.patch","issue_url":"https://api.github.com/repos/typelevel/cats/issues/1571","number":1571,"state":"open","locked":false,"title":"added whileM, untilM, iterateWhile, etc to Monad","user":{"login":"kailuowang","id":83257,"avatar_url":"https://avatars0.githubusercontent.com/u/83257?v=3","gravatar_id":"","url":"https://api.github.com/users/kailuowang","html_url":"https://github.com/kailuowang","followers_url":"https://api.github.com/users/kailuowang/followers","following_url":"https://api.github.com/users/kailuowang/following{/other_user}","gists_url":"https://api.github.com/users/kailuowang/gists{/gist_id}","starred_url":"https://api.github.com/users/kailuowang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kailuowang/subscriptions","organizations_url":"https://api.github.com/users/kailuowang/orgs","repos_url":"https://api.github.com/users/kailuowang/repos","events_url":"https://api.github.com/users/kailuowang/events{/privacy}","received_events_url":"https://api.github.com/users/kailuowang/received_events","type":"User","site_admin":false},"body":"Continuation on #1216. I didn't add the other methods yet because I want to make sure I get the tests right first. There are no tests present in either original PR or Scalaz . \r\ncc @tpolecat @johnynek \r\n\r\nFixes #1569. ","created_at":"2017-03-24T15:20:58Z","updated_at":"2017-03-30T18:03:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e647aaaea7f21cb67ec96af3847823aa22536229","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/typelevel/cats/pulls/1571/commits","review_comments_url":"https://api.github.com/repos/typelevel/cats/pulls/1571/comments","review_comment_url":"https://api.github.com/repos/typelevel/cats/pulls/comments{/number}","comments_url":"https://api.github.com/repos/typelevel/cats/issues/1571/comments","statuses_url":"https://api.github.com/repos/typelevel/cats/statuses/5d173f14b14ced058d16a6eb535481ae0c5f8e0a","head":{"label":"kailuowang:add-whileM","ref":"add-whileM","sha":"5d173f14b14ced058d16a6eb535481ae0c5f8e0a","user":{"login":"kailuowang","id":83257,"avatar_url":"https://avatars0.githubusercontent.com/u/83257?v=3","gravatar_id":"","url":"https://api.github.com/users/kailuowang","html_url":"https://github.com/kailuowang","followers_url":"https://api.github.com/users/kailuowang/followers","following_url":"https://api.github.com/users/kailuowang/following{/other_user}","gists_url":"https://api.github.com/users/kailuowang/gists{/gist_id}","starred_url":"https://api.github.com/users/kailuowang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kailuowang/subscriptions","organizations_url":"https://api.github.com/users/kailuowang/orgs","repos_url":"https://api.github.com/users/kailuowang/repos","events_url":"https://api.github.com/users/kailuowang/events{/privacy}","received_events_url":"https://api.github.com/users/kailuowang/received_events","type":"User","site_admin":false},"repo":{"id":52912604,"name":"cats","full_name":"kailuowang/cats","owner":{"login":"kailuowang","id":83257,"avatar_url":"https://avatars0.githubusercontent.com/u/83257?v=3","gravatar_id":"","url":"https://api.github.com/users/kailuowang","html_url":"https://github.com/kailuowang","followers_url":"https://api.github.com/users/kailuowang/followers","following_url":"https://api.github.com/users/kailuowang/following{/other_user}","gists_url":"https://api.github.com/users/kailuowang/gists{/gist_id}","starred_url":"https://api.github.com/users/kailuowang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kailuowang/subscriptions","organizations_url":"https://api.github.com/users/kailuowang/orgs","repos_url":"https://api.github.com/users/kailuowang/repos","events_url":"https://api.github.com/users/kailuowang/events{/privacy}","received_events_url":"https://api.github.com/users/kailuowang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kailuowang/cats","description":"Lightweight, modular, and extensible library for functional programming.","fork":true,"url":"https://api.github.com/repos/kailuowang/cats","forks_url":"https://api.github.com/repos/kailuowang/cats/forks","keys_url":"https://api.github.com/repos/kailuowang/cats/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kailuowang/cats/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kailuowang/cats/teams","hooks_url":"https://api.github.com/repos/kailuowang/cats/hooks","issue_events_url":"https://api.github.com/repos/kailuowang/cats/issues/events{/number}","events_url":"https://api.github.com/repos/kailuowang/cats/events","assignees_url":"https://api.github.com/repos/kailuowang/cats/assignees{/user}","branches_url":"https://api.github.com/repos/kailuowang/cats/branches{/branch}","tags_url":"https://api.github.com/repos/kailuowang/cats/tags","blobs_url":"https://api.github.com/repos/kailuowang/cats/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kailuowang/cats/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kailuowang/cats/git/refs{/sha}","trees_url":"https://api.github.com/repos/kailuowang/cats/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kailuowang/cats/statuses/{sha}","languages_url":"https://api.github.com/repos/kailuowang/cats/languages","stargazers_url":"https://api.github.com/repos/kailuowang/cats/stargazers","contributors_url":"https://api.github.com/repos/kailuowang/cats/contributors","subscribers_url":"https://api.github.com/repos/kailuowang/cats/subscribers","subscription_url":"https://api.github.com/repos/kailuowang/cats/subscription","commits_url":"https://api.github.com/repos/kailuowang/cats/commits{/sha}","git_commits_url":"https://api.github.com/repos/kailuowang/cats/git/commits{/sha}","comments_url":"https://api.github.com/repos/kailuowang/cats/comments{/number}","issue_comment_url":"https://api.github.com/repos/kailuowang/cats/issues/comments{/number}","contents_url":"https://api.github.com/repos/kailuowang/cats/contents/{+path}","compare_url":"https://api.github.com/repos/kailuowang/cats/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kailuowang/cats/merges","archive_url":"https://api.github.com/repos/kailuowang/cats/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kailuowang/cats/downloads","issues_url":"https://api.github.com/repos/kailuowang/cats/issues{/number}","pulls_url":"https://api.github.com/repos/kailuowang/cats/pulls{/number}","milestones_url":"https://api.github.com/repos/kailuowang/cats/milestones{/number}","notifications_url":"https://api.github.com/repos/kailuowang/cats/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kailuowang/cats/labels{/name}","releases_url":"https://api.github.com/repos/kailuowang/cats/releases{/id}","deployments_url":"https://api.github.com/repos/kailuowang/cats/deployments","created_at":"2016-03-01T21:49:31Z","updated_at":"2016-03-01T21:49:33Z","pushed_at":"2017-03-27T15:35:12Z","git_url":"git://github.com/kailuowang/cats.git","ssh_url":"git@github.com:kailuowang/cats.git","clone_url":"https://github.com/kailuowang/cats.git","svn_url":"https://github.com/kailuowang/cats","homepage":"http://typelevel.org/cats/","size":10050,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_projects":true,"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":"typelevel:master","ref":"master","sha":"18c906bf1e859c66f00f21e18ad10d231c525245","user":{"login":"typelevel","id":3731824,"avatar_url":"https://avatars3.githubusercontent.com/u/3731824?v=3","gravatar_id":"","url":"https://api.github.com/users/typelevel","html_url":"https://github.com/typelevel","followers_url":"https://api.github.com/users/typelevel/followers","following_url":"https://api.github.com/users/typelevel/following{/other_user}","gists_url":"https://api.github.com/users/typelevel/gists{/gist_id}","starred_url":"https://api.github.com/users/typelevel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/typelevel/subscriptions","organizations_url":"https://api.github.com/users/typelevel/orgs","repos_url":"https://api.github.com/users/typelevel/repos","events_url":"https://api.github.com/users/typelevel/events{/privacy}","received_events_url":"https://api.github.com/users/typelevel/received_events","type":"Organization","site_admin":false},"repo":{"id":29986727,"name":"cats","full_name":"typelevel/cats","owner":{"login":"typelevel","id":3731824,"avatar_url":"https://avatars3.githubusercontent.com/u/3731824?v=3","gravatar_id":"","url":"https://api.github.com/users/typelevel","html_url":"https://github.com/typelevel","followers_url":"https://api.github.com/users/typelevel/followers","following_url":"https://api.github.com/users/typelevel/following{/other_user}","gists_url":"https://api.github.com/users/typelevel/gists{/gist_id}","starred_url":"https://api.github.com/users/typelevel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/typelevel/subscriptions","organizations_url":"https://api.github.com/users/typelevel/orgs","repos_url":"https://api.github.com/users/typelevel/repos","events_url":"https://api.github.com/users/typelevel/events{/privacy}","received_events_url":"https://api.github.com/users/typelevel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/typelevel/cats","description":"Lightweight, modular, and extensible library for functional programming.","fork":false,"url":"https://api.github.com/repos/typelevel/cats","forks_url":"https://api.github.com/repos/typelevel/cats/forks","keys_url":"https://api.github.com/repos/typelevel/cats/keys{/key_id}","collaborators_url":"https://api.github.com/repos/typelevel/cats/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/typelevel/cats/teams","hooks_url":"https://api.github.com/repos/typelevel/cats/hooks","issue_events_url":"https://api.github.com/repos/typelevel/cats/issues/events{/number}","events_url":"https://api.github.com/repos/typelevel/cats/events","assignees_url":"https://api.github.com/repos/typelevel/cats/assignees{/user}","branches_url":"https://api.github.com/repos/typelevel/cats/branches{/branch}","tags_url":"https://api.github.com/repos/typelevel/cats/tags","blobs_url":"https://api.github.com/repos/typelevel/cats/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/typelevel/cats/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/typelevel/cats/git/refs{/sha}","trees_url":"https://api.github.com/repos/typelevel/cats/git/trees{/sha}","statuses_url":"https://api.github.com/repos/typelevel/cats/statuses/{sha}","languages_url":"https://api.github.com/repos/typelevel/cats/languages","stargazers_url":"https://api.github.com/repos/typelevel/cats/stargazers","contributors_url":"https://api.github.com/repos/typelevel/cats/contributors","subscribers_url":"https://api.github.com/repos/typelevel/cats/subscribers","subscription_url":"https://api.github.com/repos/typelevel/cats/subscription","commits_url":"https://api.github.com/repos/typelevel/cats/commits{/sha}","git_commits_url":"https://api.github.com/repos/typelevel/cats/git/commits{/sha}","comments_url":"https://api.github.com/repos/typelevel/cats/comments{/number}","issue_comment_url":"https://api.github.com/repos/typelevel/cats/issues/comments{/number}","contents_url":"https://api.github.com/repos/typelevel/cats/contents/{+path}","compare_url":"https://api.github.com/repos/typelevel/cats/compare/{base}...{head}","merges_url":"https://api.github.com/repos/typelevel/cats/merges","archive_url":"https://api.github.com/repos/typelevel/cats/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/typelevel/cats/downloads","issues_url":"https://api.github.com/repos/typelevel/cats/issues{/number}","pulls_url":"https://api.github.com/repos/typelevel/cats/pulls{/number}","milestones_url":"https://api.github.com/repos/typelevel/cats/milestones{/number}","notifications_url":"https://api.github.com/repos/typelevel/cats/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/typelevel/cats/labels{/name}","releases_url":"https://api.github.com/repos/typelevel/cats/releases{/id}","deployments_url":"https://api.github.com/repos/typelevel/cats/deployments","created_at":"2015-01-28T20:26:48Z","updated_at":"2017-03-30T15:03:55Z","pushed_at":"2017-03-30T17:04:20Z","git_url":"git://github.com/typelevel/cats.git","ssh_url":"git@github.com:typelevel/cats.git","clone_url":"https://github.com/typelevel/cats.git","svn_url":"https://github.com/typelevel/cats","homepage":"http://typelevel.org/cats/","size":15858,"stargazers_count":1654,"watchers_count":1654,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":390,"mirror_url":null,"open_issues_count":224,"forks":390,"open_issues":224,"watchers":1654,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/typelevel/cats/pulls/1571"},"html":{"href":"https://github.com/typelevel/cats/pull/1571"},"issue":{"href":"https://api.github.com/repos/typelevel/cats/issues/1571"},"comments":{"href":"https://api.github.com/repos/typelevel/cats/issues/1571/comments"},"review_comments":{"href":"https://api.github.com/repos/typelevel/cats/pulls/1571/comments"},"review_comment":{"href":"https://api.github.com/repos/typelevel/cats/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/typelevel/cats/pulls/1571/commits"},"statuses":{"href":"https://api.github.com/repos/typelevel/cats/statuses/5d173f14b14ced058d16a6eb535481ae0c5f8e0a"}}}}
{"actor":{"display_login":"tpolecat"}}