{"action":"created","comment":{"url":"https://api.github.com/repos/scala/docs.scala-lang/pulls/comments/226509371","pull_request_review_id":166349542,"id":226509371,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNjUwOTM3MQ==","diff_hunk":"@@ -13,3 +13,140 @@ language: zh-cn\n next-page: singleton-objects\n previous-page: case-classes\n ---\n+\n+模式匹配是检查某个值（value）是否匹配某一个模式的机制，一个成功的匹配同时会将匹配值解构为其组成部分。它是Java中的`switch`语句的升级版，同样可以用于替代一系列的 if/else 语句。\n+\n+## 语法\n+一个模式匹配语句包括一个待匹配的值，`match`关键字，以及至少一个`case`语句。\n+\n+```tut\n+import scala.util.Random\n+\n+val x: Int = Random.nextInt(10)\n+\n+x match {\n+  case 0 => \"zero\"\n+  case 1 => \"one\"\n+  case 2 => \"two\"\n+  case _ => \"many\"\n+}\n+```\n+上述代码中的`val x`是一个0到10之间的随机整数，将它放在`match`运算符的左侧对其进行模式匹配，`match`的右侧是包含4条`case`的表达式，其中最后一个`case _`表示匹配其余所有情况，在这里即是`x`大于2的情况。","path":"_zh-cn/tour/pattern-matching.md","position":30,"original_position":30,"commit_id":"46a4231face6fa41f5118bc803f410aee4a3a317","original_commit_id":"46a4231face6fa41f5118bc803f410aee4a3a317","user":{"login":"dongxuwang","id":4261431,"node_id":"MDQ6VXNlcjQyNjE0MzE=","avatar_url":"https://avatars1.githubusercontent.com/u/4261431?v=4","gravatar_id":"","url":"https://api.github.com/users/dongxuwang","html_url":"https://github.com/dongxuwang","followers_url":"https://api.github.com/users/dongxuwang/followers","following_url":"https://api.github.com/users/dongxuwang/following{/other_user}","gists_url":"https://api.github.com/users/dongxuwang/gists{/gist_id}","starred_url":"https://api.github.com/users/dongxuwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dongxuwang/subscriptions","organizations_url":"https://api.github.com/users/dongxuwang/orgs","repos_url":"https://api.github.com/users/dongxuwang/repos","events_url":"https://api.github.com/users/dongxuwang/events{/privacy}","received_events_url":"https://api.github.com/users/dongxuwang/received_events","type":"User","site_admin":false},"body":"Agree, so that's why you ignored it.","created_at":"2018-10-19T01:07:28Z","updated_at":"2018-10-19T01:07:28Z","html_url":"https://github.com/scala/docs.scala-lang/pull/1177#discussion_r226509371","pull_request_url":"https://api.github.com/repos/scala/docs.scala-lang/pulls/1177","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/scala/docs.scala-lang/pulls/comments/226509371"},"html":{"href":"https://github.com/scala/docs.scala-lang/pull/1177#discussion_r226509371"},"pull_request":{"href":"https://api.github.com/repos/scala/docs.scala-lang/pulls/1177"}},"in_reply_to_id":226188393},"pull_request":{"url":"https://api.github.com/repos/scala/docs.scala-lang/pulls/1177","id":222369012,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIyMzY5MDEy","html_url":"https://github.com/scala/docs.scala-lang/pull/1177","diff_url":"https://github.com/scala/docs.scala-lang/pull/1177.diff","patch_url":"https://github.com/scala/docs.scala-lang/pull/1177.patch","issue_url":"https://api.github.com/repos/scala/docs.scala-lang/issues/1177","number":1177,"state":"open","locked":false,"title":"zh-cn for Scala Toor: Pattern matching","user":{"login":"declan94","id":14135652,"node_id":"MDQ6VXNlcjE0MTM1NjUy","avatar_url":"https://avatars3.githubusercontent.com/u/14135652?v=4","gravatar_id":"","url":"https://api.github.com/users/declan94","html_url":"https://github.com/declan94","followers_url":"https://api.github.com/users/declan94/followers","following_url":"https://api.github.com/users/declan94/following{/other_user}","gists_url":"https://api.github.com/users/declan94/gists{/gist_id}","starred_url":"https://api.github.com/users/declan94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/declan94/subscriptions","organizations_url":"https://api.github.com/users/declan94/orgs","repos_url":"https://api.github.com/users/declan94/repos","events_url":"https://api.github.com/users/declan94/events{/privacy}","received_events_url":"https://api.github.com/users/declan94/received_events","type":"User","site_admin":false},"body":"Simplified Chinese version for Scala Toor: Pattern matching","created_at":"2018-10-12T07:05:50Z","updated_at":"2018-10-19T01:07:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ba281083acbcf70bb7396aca3abb379d5f070842","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/scala/docs.scala-lang/pulls/1177/commits","review_comments_url":"https://api.github.com/repos/scala/docs.scala-lang/pulls/1177/comments","review_comment_url":"https://api.github.com/repos/scala/docs.scala-lang/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scala/docs.scala-lang/issues/1177/comments","statuses_url":"https://api.github.com/repos/scala/docs.scala-lang/statuses/46a4231face6fa41f5118bc803f410aee4a3a317","head":{"label":"declan94:pattern_matching","ref":"pattern_matching","sha":"46a4231face6fa41f5118bc803f410aee4a3a317","user":{"login":"declan94","id":14135652,"node_id":"MDQ6VXNlcjE0MTM1NjUy","avatar_url":"https://avatars3.githubusercontent.com/u/14135652?v=4","gravatar_id":"","url":"https://api.github.com/users/declan94","html_url":"https://github.com/declan94","followers_url":"https://api.github.com/users/declan94/followers","following_url":"https://api.github.com/users/declan94/following{/other_user}","gists_url":"https://api.github.com/users/declan94/gists{/gist_id}","starred_url":"https://api.github.com/users/declan94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/declan94/subscriptions","organizations_url":"https://api.github.com/users/declan94/orgs","repos_url":"https://api.github.com/users/declan94/repos","events_url":"https://api.github.com/users/declan94/events{/privacy}","received_events_url":"https://api.github.com/users/declan94/received_events","type":"User","site_admin":false},"repo":{"id":150220492,"node_id":"MDEwOlJlcG9zaXRvcnkxNTAyMjA0OTI=","name":"docs.scala-lang","full_name":"declan94/docs.scala-lang","private":false,"owner":{"login":"declan94","id":14135652,"node_id":"MDQ6VXNlcjE0MTM1NjUy","avatar_url":"https://avatars3.githubusercontent.com/u/14135652?v=4","gravatar_id":"","url":"https://api.github.com/users/declan94","html_url":"https://github.com/declan94","followers_url":"https://api.github.com/users/declan94/followers","following_url":"https://api.github.com/users/declan94/following{/other_user}","gists_url":"https://api.github.com/users/declan94/gists{/gist_id}","starred_url":"https://api.github.com/users/declan94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/declan94/subscriptions","organizations_url":"https://api.github.com/users/declan94/orgs","repos_url":"https://api.github.com/users/declan94/repos","events_url":"https://api.github.com/users/declan94/events{/privacy}","received_events_url":"https://api.github.com/users/declan94/received_events","type":"User","site_admin":false},"html_url":"https://github.com/declan94/docs.scala-lang","description":"The Scala Documentation website","fork":true,"url":"https://api.github.com/repos/declan94/docs.scala-lang","forks_url":"https://api.github.com/repos/declan94/docs.scala-lang/forks","keys_url":"https://api.github.com/repos/declan94/docs.scala-lang/keys{/key_id}","collaborators_url":"https://api.github.com/repos/declan94/docs.scala-lang/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/declan94/docs.scala-lang/teams","hooks_url":"https://api.github.com/repos/declan94/docs.scala-lang/hooks","issue_events_url":"https://api.github.com/repos/declan94/docs.scala-lang/issues/events{/number}","events_url":"https://api.github.com/repos/declan94/docs.scala-lang/events","assignees_url":"https://api.github.com/repos/declan94/docs.scala-lang/assignees{/user}","branches_url":"https://api.github.com/repos/declan94/docs.scala-lang/branches{/branch}","tags_url":"https://api.github.com/repos/declan94/docs.scala-lang/tags","blobs_url":"https://api.github.com/repos/declan94/docs.scala-lang/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/declan94/docs.scala-lang/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/declan94/docs.scala-lang/git/refs{/sha}","trees_url":"https://api.github.com/repos/declan94/docs.scala-lang/git/trees{/sha}","statuses_url":"https://api.github.com/repos/declan94/docs.scala-lang/statuses/{sha}","languages_url":"https://api.github.com/repos/declan94/docs.scala-lang/languages","stargazers_url":"https://api.github.com/repos/declan94/docs.scala-lang/stargazers","contributors_url":"https://api.github.com/repos/declan94/docs.scala-lang/contributors","subscribers_url":"https://api.github.com/repos/declan94/docs.scala-lang/subscribers","subscription_url":"https://api.github.com/repos/declan94/docs.scala-lang/subscription","commits_url":"https://api.github.com/repos/declan94/docs.scala-lang/commits{/sha}","git_commits_url":"https://api.github.com/repos/declan94/docs.scala-lang/git/commits{/sha}","comments_url":"https://api.github.com/repos/declan94/docs.scala-lang/comments{/number}","issue_comment_url":"https://api.github.com/repos/declan94/docs.scala-lang/issues/comments{/number}","contents_url":"https://api.github.com/repos/declan94/docs.scala-lang/contents/{+path}","compare_url":"https://api.github.com/repos/declan94/docs.scala-lang/compare/{base}...{head}","merges_url":"https://api.github.com/repos/declan94/docs.scala-lang/merges","archive_url":"https://api.github.com/repos/declan94/docs.scala-lang/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/declan94/docs.scala-lang/downloads","issues_url":"https://api.github.com/repos/declan94/docs.scala-lang/issues{/number}","pulls_url":"https://api.github.com/repos/declan94/docs.scala-lang/pulls{/number}","milestones_url":"https://api.github.com/repos/declan94/docs.scala-lang/milestones{/number}","notifications_url":"https://api.github.com/repos/declan94/docs.scala-lang/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/declan94/docs.scala-lang/labels{/name}","releases_url":"https://api.github.com/repos/declan94/docs.scala-lang/releases{/id}","deployments_url":"https://api.github.com/repos/declan94/docs.scala-lang/deployments","created_at":"2018-09-25T06:52:46Z","updated_at":"2018-10-12T05:50:46Z","pushed_at":"2018-10-17T08:38:06Z","git_url":"git://github.com/declan94/docs.scala-lang.git","ssh_url":"git@github.com:declan94/docs.scala-lang.git","clone_url":"https://github.com/declan94/docs.scala-lang.git","svn_url":"https://github.com/declan94/docs.scala-lang","homepage":"http://docs.scala-lang.org","size":18645,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scala:master","ref":"master","sha":"f34e341a1f71cce70708f12dbe3e7f2e77f3055e","user":{"login":"scala","id":57059,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU3MDU5","avatar_url":"https://avatars2.githubusercontent.com/u/57059?v=4","gravatar_id":"","url":"https://api.github.com/users/scala","html_url":"https://github.com/scala","followers_url":"https://api.github.com/users/scala/followers","following_url":"https://api.github.com/users/scala/following{/other_user}","gists_url":"https://api.github.com/users/scala/gists{/gist_id}","starred_url":"https://api.github.com/users/scala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala/subscriptions","organizations_url":"https://api.github.com/users/scala/orgs","repos_url":"https://api.github.com/users/scala/repos","events_url":"https://api.github.com/users/scala/events{/privacy}","received_events_url":"https://api.github.com/users/scala/received_events","type":"Organization","site_admin":false},"repo":{"id":2577071,"node_id":"MDEwOlJlcG9zaXRvcnkyNTc3MDcx","name":"docs.scala-lang","full_name":"scala/docs.scala-lang","private":false,"owner":{"login":"scala","id":57059,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU3MDU5","avatar_url":"https://avatars2.githubusercontent.com/u/57059?v=4","gravatar_id":"","url":"https://api.github.com/users/scala","html_url":"https://github.com/scala","followers_url":"https://api.github.com/users/scala/followers","following_url":"https://api.github.com/users/scala/following{/other_user}","gists_url":"https://api.github.com/users/scala/gists{/gist_id}","starred_url":"https://api.github.com/users/scala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala/subscriptions","organizations_url":"https://api.github.com/users/scala/orgs","repos_url":"https://api.github.com/users/scala/repos","events_url":"https://api.github.com/users/scala/events{/privacy}","received_events_url":"https://api.github.com/users/scala/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/scala/docs.scala-lang","description":"The Scala Documentation website","fork":false,"url":"https://api.github.com/repos/scala/docs.scala-lang","forks_url":"https://api.github.com/repos/scala/docs.scala-lang/forks","keys_url":"https://api.github.com/repos/scala/docs.scala-lang/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scala/docs.scala-lang/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scala/docs.scala-lang/teams","hooks_url":"https://api.github.com/repos/scala/docs.scala-lang/hooks","issue_events_url":"https://api.github.com/repos/scala/docs.scala-lang/issues/events{/number}","events_url":"https://api.github.com/repos/scala/docs.scala-lang/events","assignees_url":"https://api.github.com/repos/scala/docs.scala-lang/assignees{/user}","branches_url":"https://api.github.com/repos/scala/docs.scala-lang/branches{/branch}","tags_url":"https://api.github.com/repos/scala/docs.scala-lang/tags","blobs_url":"https://api.github.com/repos/scala/docs.scala-lang/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scala/docs.scala-lang/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scala/docs.scala-lang/git/refs{/sha}","trees_url":"https://api.github.com/repos/scala/docs.scala-lang/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scala/docs.scala-lang/statuses/{sha}","languages_url":"https://api.github.com/repos/scala/docs.scala-lang/languages","stargazers_url":"https://api.github.com/repos/scala/docs.scala-lang/stargazers","contributors_url":"https://api.github.com/repos/scala/docs.scala-lang/contributors","subscribers_url":"https://api.github.com/repos/scala/docs.scala-lang/subscribers","subscription_url":"https://api.github.com/repos/scala/docs.scala-lang/subscription","commits_url":"https://api.github.com/repos/scala/docs.scala-lang/commits{/sha}","git_commits_url":"https://api.github.com/repos/scala/docs.scala-lang/git/commits{/sha}","comments_url":"https://api.github.com/repos/scala/docs.scala-lang/comments{/number}","issue_comment_url":"https://api.github.com/repos/scala/docs.scala-lang/issues/comments{/number}","contents_url":"https://api.github.com/repos/scala/docs.scala-lang/contents/{+path}","compare_url":"https://api.github.com/repos/scala/docs.scala-lang/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scala/docs.scala-lang/merges","archive_url":"https://api.github.com/repos/scala/docs.scala-lang/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scala/docs.scala-lang/downloads","issues_url":"https://api.github.com/repos/scala/docs.scala-lang/issues{/number}","pulls_url":"https://api.github.com/repos/scala/docs.scala-lang/pulls{/number}","milestones_url":"https://api.github.com/repos/scala/docs.scala-lang/milestones{/number}","notifications_url":"https://api.github.com/repos/scala/docs.scala-lang/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scala/docs.scala-lang/labels{/name}","releases_url":"https://api.github.com/repos/scala/docs.scala-lang/releases{/id}","deployments_url":"https://api.github.com/repos/scala/docs.scala-lang/deployments","created_at":"2011-10-14T15:37:14Z","updated_at":"2018-10-18T10:25:08Z","pushed_at":"2018-10-18T10:25:03Z","git_url":"git://github.com/scala/docs.scala-lang.git","ssh_url":"git@github.com:scala/docs.scala-lang.git","clone_url":"https://github.com/scala/docs.scala-lang.git","svn_url":"https://github.com/scala/docs.scala-lang","homepage":"http://docs.scala-lang.org","size":18723,"stargazers_count":359,"watchers_count":359,"language":"HTML","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":495,"mirror_url":null,"archived":false,"open_issues_count":51,"license":null,"forks":495,"open_issues":51,"watchers":359,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scala/docs.scala-lang/pulls/1177"},"html":{"href":"https://github.com/scala/docs.scala-lang/pull/1177"},"issue":{"href":"https://api.github.com/repos/scala/docs.scala-lang/issues/1177"},"comments":{"href":"https://api.github.com/repos/scala/docs.scala-lang/issues/1177/comments"},"review_comments":{"href":"https://api.github.com/repos/scala/docs.scala-lang/pulls/1177/comments"},"review_comment":{"href":"https://api.github.com/repos/scala/docs.scala-lang/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scala/docs.scala-lang/pulls/1177/commits"},"statuses":{"href":"https://api.github.com/repos/scala/docs.scala-lang/statuses/46a4231face6fa41f5118bc803f410aee4a3a317"}},"author_association":"NONE"}}
{"actor":{"display_login":"dongxuwang"}}