{"action":"created","comment":{"url":"https://api.github.com/repos/typelevel/paiges/pulls/comments/211477790","pull_request_review_id":147903937,"id":211477790,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMTQ3Nzc5MA==","diff_hunk":"@@ -443,60 +449,25 @@ sealed abstract class Doc extends Product with Serializable {\n     loop(Left(this) :: Nil, Doc.empty)\n   }\n \n-  /**\n-   * This method is similar to flatten, but returns None if no\n-   * flattening was needed (i.e. if no newlines or unions were present).\n-   *\n-   * As with flatten, the resulting Doc (if any) will never render any\n-   * newlines, no matter what width is used.\n-   */\n-  def flattenOption: Option[Doc] = {\n-    val res = flattenBoolean\n-    if (res._2) Some(res._1) else None\n-  }\n-\n-  /**\n-   * Convert this Doc to a single-line representation.\n-   *\n-   * All newlines are replaced with spaces (and optional indentation\n-   * is ignored). The resulting Doc will never render any newlines, no\n-   * matter what width is used.\n-   */\n-  def flatten: Doc = flattenBoolean._1\n-\n-  // return the flattened doc, and if it is different\n-  private def flattenBoolean: (Doc, Boolean) = {\n+  private[paiges] def flatten: Doc = flattenBoolean._1\n \n+  private[paiges] def flattenBoolean: (Doc, Boolean) = {\n     type DB = (Doc, Boolean)\n \n-    def finish(last: DB, front: List[DB]): DB =\n-      front.foldLeft(last) {\n-        case ((d1, c1), (d0, c2)) => (Concat(d0, d1), c1 || c2)\n-      }\n-\n     @tailrec\n-    def loop(h: DB, stack: List[DB], front: List[DB]): DB =\n-      h._1 match {\n-        case Empty | Text(_) =>\n-          stack match {\n-            case Nil => finish(h, front)\n-            case x :: xs => loop(x, xs, h :: front)\n-          }\n-        case l@Line(_) =>\n-          val next = l.asFlatDoc\n-          val change = (next, true)\n-          stack match {\n-            case Nil => finish(change, front)\n-            case x :: xs => loop(x, xs, change :: front)\n-          }\n-        case Nest(i, d) =>\n-          loop((d, h._2), stack, front) // no Line, so Nest is irrelevant\n-        case Align(d) =>\n-          loop((d, h._2), stack, front) // no Line, so Align is irrelevant\n-        case LazyDoc(d) => loop((d.evaluated, h._2), stack, front)\n-        case Union(a, _) => loop((a, true), stack, front) // invariant: flatten(union(a, b)) == flatten(a)\n-        case Concat(a, b) => loop((a, h._2), (b, h._2) :: stack, front)\n+    def loop(h: DB, lst: List[DB], ks: List[DB => DB]): DB = h._1 match {","path":"core/src/main/scala/org/typelevel/paiges/Doc.scala","position":null,"original_position":164,"commit_id":"7873f10445ffd26fde764f1384932c0119e1123a","original_commit_id":"5b42b3401d184d5858a1adaa79f1b1045d041362","user":{"login":"seanmcl","id":110393,"node_id":"MDQ6VXNlcjExMDM5Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/110393?v=4","gravatar_id":"","url":"https://api.github.com/users/seanmcl","html_url":"https://github.com/seanmcl","followers_url":"https://api.github.com/users/seanmcl/followers","following_url":"https://api.github.com/users/seanmcl/following{/other_user}","gists_url":"https://api.github.com/users/seanmcl/gists{/gist_id}","starred_url":"https://api.github.com/users/seanmcl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seanmcl/subscriptions","organizations_url":"https://api.github.com/users/seanmcl/orgs","repos_url":"https://api.github.com/users/seanmcl/repos","events_url":"https://api.github.com/users/seanmcl/events{/privacy}","received_events_url":"https://api.github.com/users/seanmcl/received_events","type":"User","site_admin":false},"body":"OK, I removed `Fail` and have more or less what you proposed.  The only wrinkle is in my testing of `fill` I needed some invariants on non-flattenable documents, so I write a `normalize` method that I apply to such documents.  I didn't see an obvious way to make it tail recursive, so I left it in the normal recursive style.  I figured if you're happy with the change, I can spend more effort to make it tail recursive.  ","created_at":"2018-08-21T04:51:42Z","updated_at":"2018-08-21T04:51:42Z","html_url":"https://github.com/typelevel/paiges/pull/117#discussion_r211477790","pull_request_url":"https://api.github.com/repos/typelevel/paiges/pulls/117","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/typelevel/paiges/pulls/comments/211477790"},"html":{"href":"https://github.com/typelevel/paiges/pull/117#discussion_r211477790"},"pull_request":{"href":"https://api.github.com/repos/typelevel/paiges/pulls/117"}},"in_reply_to_id":211297181},"pull_request":{"url":"https://api.github.com/repos/typelevel/paiges/pulls/117","id":206496601,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA2NDk2NjAx","html_url":"https://github.com/typelevel/paiges/pull/117","diff_url":"https://github.com/typelevel/paiges/pull/117.diff","patch_url":"https://github.com/typelevel/paiges/pull/117.patch","issue_url":"https://api.github.com/repos/typelevel/paiges/issues/117","number":117,"state":"open","locked":false,"title":"Add FlatAlt to support hard line breaks","user":{"login":"seanmcl","id":110393,"node_id":"MDQ6VXNlcjExMDM5Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/110393?v=4","gravatar_id":"","url":"https://api.github.com/users/seanmcl","html_url":"https://github.com/seanmcl","followers_url":"https://api.github.com/users/seanmcl/followers","following_url":"https://api.github.com/users/seanmcl/following{/other_user}","gists_url":"https://api.github.com/users/seanmcl/gists{/gist_id}","starred_url":"https://api.github.com/users/seanmcl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seanmcl/subscriptions","organizations_url":"https://api.github.com/users/seanmcl/orgs","repos_url":"https://api.github.com/users/seanmcl/repos","events_url":"https://api.github.com/users/seanmcl/events{/privacy}","received_events_url":"https://api.github.com/users/seanmcl/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-08-06T19:39:44Z","updated_at":"2018-08-21T04:51:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2e299e6aa671051fc826aa39846be7a67910b842","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/typelevel/paiges/pulls/117/commits","review_comments_url":"https://api.github.com/repos/typelevel/paiges/pulls/117/comments","review_comment_url":"https://api.github.com/repos/typelevel/paiges/pulls/comments{/number}","comments_url":"https://api.github.com/repos/typelevel/paiges/issues/117/comments","statuses_url":"https://api.github.com/repos/typelevel/paiges/statuses/7873f10445ffd26fde764f1384932c0119e1123a","head":{"label":"seanmcl:sm/hard2","ref":"sm/hard2","sha":"7873f10445ffd26fde764f1384932c0119e1123a","user":{"login":"seanmcl","id":110393,"node_id":"MDQ6VXNlcjExMDM5Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/110393?v=4","gravatar_id":"","url":"https://api.github.com/users/seanmcl","html_url":"https://github.com/seanmcl","followers_url":"https://api.github.com/users/seanmcl/followers","following_url":"https://api.github.com/users/seanmcl/following{/other_user}","gists_url":"https://api.github.com/users/seanmcl/gists{/gist_id}","starred_url":"https://api.github.com/users/seanmcl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seanmcl/subscriptions","organizations_url":"https://api.github.com/users/seanmcl/orgs","repos_url":"https://api.github.com/users/seanmcl/repos","events_url":"https://api.github.com/users/seanmcl/events{/privacy}","received_events_url":"https://api.github.com/users/seanmcl/received_events","type":"User","site_admin":false},"repo":{"id":94467926,"node_id":"MDEwOlJlcG9zaXRvcnk5NDQ2NzkyNg==","name":"paiges","full_name":"seanmcl/paiges","owner":{"login":"seanmcl","id":110393,"node_id":"MDQ6VXNlcjExMDM5Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/110393?v=4","gravatar_id":"","url":"https://api.github.com/users/seanmcl","html_url":"https://github.com/seanmcl","followers_url":"https://api.github.com/users/seanmcl/followers","following_url":"https://api.github.com/users/seanmcl/following{/other_user}","gists_url":"https://api.github.com/users/seanmcl/gists{/gist_id}","starred_url":"https://api.github.com/users/seanmcl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seanmcl/subscriptions","organizations_url":"https://api.github.com/users/seanmcl/orgs","repos_url":"https://api.github.com/users/seanmcl/repos","events_url":"https://api.github.com/users/seanmcl/events{/privacy}","received_events_url":"https://api.github.com/users/seanmcl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/seanmcl/paiges","description":"an implementation of Wadler's a prettier printer","fork":true,"url":"https://api.github.com/repos/seanmcl/paiges","forks_url":"https://api.github.com/repos/seanmcl/paiges/forks","keys_url":"https://api.github.com/repos/seanmcl/paiges/keys{/key_id}","collaborators_url":"https://api.github.com/repos/seanmcl/paiges/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/seanmcl/paiges/teams","hooks_url":"https://api.github.com/repos/seanmcl/paiges/hooks","issue_events_url":"https://api.github.com/repos/seanmcl/paiges/issues/events{/number}","events_url":"https://api.github.com/repos/seanmcl/paiges/events","assignees_url":"https://api.github.com/repos/seanmcl/paiges/assignees{/user}","branches_url":"https://api.github.com/repos/seanmcl/paiges/branches{/branch}","tags_url":"https://api.github.com/repos/seanmcl/paiges/tags","blobs_url":"https://api.github.com/repos/seanmcl/paiges/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/seanmcl/paiges/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/seanmcl/paiges/git/refs{/sha}","trees_url":"https://api.github.com/repos/seanmcl/paiges/git/trees{/sha}","statuses_url":"https://api.github.com/repos/seanmcl/paiges/statuses/{sha}","languages_url":"https://api.github.com/repos/seanmcl/paiges/languages","stargazers_url":"https://api.github.com/repos/seanmcl/paiges/stargazers","contributors_url":"https://api.github.com/repos/seanmcl/paiges/contributors","subscribers_url":"https://api.github.com/repos/seanmcl/paiges/subscribers","subscription_url":"https://api.github.com/repos/seanmcl/paiges/subscription","commits_url":"https://api.github.com/repos/seanmcl/paiges/commits{/sha}","git_commits_url":"https://api.github.com/repos/seanmcl/paiges/git/commits{/sha}","comments_url":"https://api.github.com/repos/seanmcl/paiges/comments{/number}","issue_comment_url":"https://api.github.com/repos/seanmcl/paiges/issues/comments{/number}","contents_url":"https://api.github.com/repos/seanmcl/paiges/contents/{+path}","compare_url":"https://api.github.com/repos/seanmcl/paiges/compare/{base}...{head}","merges_url":"https://api.github.com/repos/seanmcl/paiges/merges","archive_url":"https://api.github.com/repos/seanmcl/paiges/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/seanmcl/paiges/downloads","issues_url":"https://api.github.com/repos/seanmcl/paiges/issues{/number}","pulls_url":"https://api.github.com/repos/seanmcl/paiges/pulls{/number}","milestones_url":"https://api.github.com/repos/seanmcl/paiges/milestones{/number}","notifications_url":"https://api.github.com/repos/seanmcl/paiges/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/seanmcl/paiges/labels{/name}","releases_url":"https://api.github.com/repos/seanmcl/paiges/releases{/id}","deployments_url":"https://api.github.com/repos/seanmcl/paiges/deployments","created_at":"2017-06-15T18:31:25Z","updated_at":"2018-08-16T14:54:31Z","pushed_at":"2018-08-21T04:48:18Z","git_url":"git://github.com/seanmcl/paiges.git","ssh_url":"git@github.com:seanmcl/paiges.git","clone_url":"https://github.com/seanmcl/paiges.git","svn_url":"https://github.com/seanmcl/paiges","homepage":null,"size":253,"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,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"typelevel:master","ref":"master","sha":"534b53357f7b1f8210f55712b39f408b7d2e10a9","user":{"login":"typelevel","id":3731824,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3MzE4MjQ=","avatar_url":"https://avatars0.githubusercontent.com/u/3731824?v=4","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":86292872,"node_id":"MDEwOlJlcG9zaXRvcnk4NjI5Mjg3Mg==","name":"paiges","full_name":"typelevel/paiges","owner":{"login":"typelevel","id":3731824,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3MzE4MjQ=","avatar_url":"https://avatars0.githubusercontent.com/u/3731824?v=4","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/paiges","description":"an implementation of Wadler's a prettier printer","fork":false,"url":"https://api.github.com/repos/typelevel/paiges","forks_url":"https://api.github.com/repos/typelevel/paiges/forks","keys_url":"https://api.github.com/repos/typelevel/paiges/keys{/key_id}","collaborators_url":"https://api.github.com/repos/typelevel/paiges/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/typelevel/paiges/teams","hooks_url":"https://api.github.com/repos/typelevel/paiges/hooks","issue_events_url":"https://api.github.com/repos/typelevel/paiges/issues/events{/number}","events_url":"https://api.github.com/repos/typelevel/paiges/events","assignees_url":"https://api.github.com/repos/typelevel/paiges/assignees{/user}","branches_url":"https://api.github.com/repos/typelevel/paiges/branches{/branch}","tags_url":"https://api.github.com/repos/typelevel/paiges/tags","blobs_url":"https://api.github.com/repos/typelevel/paiges/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/typelevel/paiges/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/typelevel/paiges/git/refs{/sha}","trees_url":"https://api.github.com/repos/typelevel/paiges/git/trees{/sha}","statuses_url":"https://api.github.com/repos/typelevel/paiges/statuses/{sha}","languages_url":"https://api.github.com/repos/typelevel/paiges/languages","stargazers_url":"https://api.github.com/repos/typelevel/paiges/stargazers","contributors_url":"https://api.github.com/repos/typelevel/paiges/contributors","subscribers_url":"https://api.github.com/repos/typelevel/paiges/subscribers","subscription_url":"https://api.github.com/repos/typelevel/paiges/subscription","commits_url":"https://api.github.com/repos/typelevel/paiges/commits{/sha}","git_commits_url":"https://api.github.com/repos/typelevel/paiges/git/commits{/sha}","comments_url":"https://api.github.com/repos/typelevel/paiges/comments{/number}","issue_comment_url":"https://api.github.com/repos/typelevel/paiges/issues/comments{/number}","contents_url":"https://api.github.com/repos/typelevel/paiges/contents/{+path}","compare_url":"https://api.github.com/repos/typelevel/paiges/compare/{base}...{head}","merges_url":"https://api.github.com/repos/typelevel/paiges/merges","archive_url":"https://api.github.com/repos/typelevel/paiges/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/typelevel/paiges/downloads","issues_url":"https://api.github.com/repos/typelevel/paiges/issues{/number}","pulls_url":"https://api.github.com/repos/typelevel/paiges/pulls{/number}","milestones_url":"https://api.github.com/repos/typelevel/paiges/milestones{/number}","notifications_url":"https://api.github.com/repos/typelevel/paiges/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/typelevel/paiges/labels{/name}","releases_url":"https://api.github.com/repos/typelevel/paiges/releases{/id}","deployments_url":"https://api.github.com/repos/typelevel/paiges/deployments","created_at":"2017-03-27T04:56:35Z","updated_at":"2018-08-20T06:40:14Z","pushed_at":"2018-08-21T04:48:20Z","git_url":"git://github.com/typelevel/paiges.git","ssh_url":"git@github.com:typelevel/paiges.git","clone_url":"https://github.com/typelevel/paiges.git","svn_url":"https://github.com/typelevel/paiges","homepage":null,"size":257,"stargazers_count":91,"watchers_count":91,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"archived":false,"open_issues_count":7,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":16,"open_issues":7,"watchers":91,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/typelevel/paiges/pulls/117"},"html":{"href":"https://github.com/typelevel/paiges/pull/117"},"issue":{"href":"https://api.github.com/repos/typelevel/paiges/issues/117"},"comments":{"href":"https://api.github.com/repos/typelevel/paiges/issues/117/comments"},"review_comments":{"href":"https://api.github.com/repos/typelevel/paiges/pulls/117/comments"},"review_comment":{"href":"https://api.github.com/repos/typelevel/paiges/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/typelevel/paiges/pulls/117/commits"},"statuses":{"href":"https://api.github.com/repos/typelevel/paiges/statuses/7873f10445ffd26fde764f1384932c0119e1123a"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"seanmcl"}}