{"id":13933023,"url":"https://github.com/ReactivePlatform/Pragmatic-Scala","last_synced_at":"2025-07-19T16:32:33.063Z","repository":{"id":19967581,"uuid":"88224459","full_name":"ReactivePlatform/Pragmatic-Scala","owner":"ReactivePlatform","description":"Pragmatic Scala 中文版——《Scala实用指南》代码清单（包含 SBT 版本（切到sbt分支））","archived":false,"fork":false,"pushed_at":"2024-07-30T00:37:57.000Z","size":1284,"stargazers_count":168,"open_issues_count":6,"forks_count":66,"subscribers_count":9,"default_branch":"sbt","last_synced_at":"2024-08-08T21:19:53.078Z","etag":null,"topics":["pragmatic-programming","pragmatic-scala","scala"],"latest_commit_sha":null,"homepage":"https://reactiveplatform.github.io/Pragmatic-Scala/","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ReactivePlatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-14T02:23:12.000Z","updated_at":"2024-07-28T15:22:43.000Z","dependencies_parsed_at":"2023-02-09T23:15:13.957Z","dependency_job_id":"872a7874-7c12-4d7c-a901-e2b19820f712","html_url":"https://github.com/ReactivePlatform/Pragmatic-Scala","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactivePlatform%2FPragmatic-Scala","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactivePlatform%2FPragmatic-Scala/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactivePlatform%2FPragmatic-Scala/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactivePlatform%2FPragmatic-Scala/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ReactivePlatform","download_url":"https://codeload.github.com/ReactivePlatform/Pragmatic-Scala/tar.gz/refs/heads/sbt","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226643924,"owners_count":17662968,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pragmatic-programming","pragmatic-scala","scala"],"created_at":"2024-08-07T21:01:29.367Z","updated_at":"2024-11-26T23:30:54.020Z","avatar_url":"https://github.com/ReactivePlatform.png","language":"Scala","readme":"# 《Scala实用指南》代码清单\n\n# 《Scala实用指南》代码清单 SBT 版本\n\n使用 [SBT](https://github.com/sbt/sbt) 作为构建工具，并按照章节形式组织的代码清单。\n\n\u003e **需要注意的是：**\u003cbr\u003e\n\u003e 我们同时还提供了基于 SC 的版本，可以直接导入到 Ammonite 或者 Scala REPL 中使用，不过部分代码清单略微有调整，请切换到 *sample* 分支。我们默认展示基于 sbt 的代码清单形式。\n\u003e 本书代码清单的在线版本，以及书中的版本都是基于的 **sbt** 分支。\n\n# 《Scala实用指南》代码清单 SBT 版本\n\n使用 [SBT](https://github.com/sbt/sbt) 作为构建工具，并按照章节形式组织的代码清单。\n## 组织形式\n\n1. `sample` 分支，原书的文件夹形式，部分代码清单可能更新到 [Ammonite Script](https://github.com/lihaoyi/Ammonite) 形式的脚本。\n2. `sbt` 分支，按照中文书章节形式组织，并且基于 SBT 构建工具进行组织，对应的代码清单大部分可以直接运行。\n\n## IDE和构建工具\n\n在工作中，大部分我们的代码都是利用构建工具和IDE进行组织和开发的。\n\n推荐的IDE或在线环境为：\n\n1. [IDEA](https://www.jetbrains.com/idea/)，同时需要安装 Scala 插件[intellij-scala](https://github.com/JetBrains/intellij-scala)\n2. [ScalaIDE](http://scala-ide.org/)\n3. [Ensime](http://ensime.github.io/)\n4. 在线的 [ScalaFiddle](https://scalafiddle.io/) 或者 [scastie](https://scastie.scala-lang.org)\n\n常用的构建工具为：\n\n- Gradle ：需要安装插件[The Scala Plugin](https://docs.gradle.org/current/userguide/scala_plugin.html)\n- Maven ：需要安装插件:\n    - [scala-maven-plugin](https://github.com/davidB/scala-maven-plugin) 或者\n    - [scalor-maven-plugin](https://github.com/random-maven/scalor-maven-plugin)\n- [Mill](https://github.com/lihaoyi/mill) ：直接支持\n- SBT : 直接支持，需要安装插件IDE插件。\n\n## 代码清单使用说明\n\n代码清单中以 `sc` 结尾的文件是 Scala Script，建议用scala命令运行，以 `scala` 结尾的文件是一般意义上的Scala代码文件。\n\n前三章建议只用scala命令行，用法参照第二章中的说明。后面的章节请使用 scala, amm, javap, sbt 等工具，灵活地探索 Scala 代码的奥秘。\n\n其中一些以 `.sc` 结尾的代码清单，并不能直接运行，这时需要借助于 [Ammonite](https://blog.jetbrains.com/scala/2018/05/07/ammonite-support/) 的力量。\n如果读者有疑问，可以直接切换到sbt分支，找到对应的文件，进行运行。\n\n\n## 代码清单使用示范\nTips:\n\n+ 对于那些以sc结尾的，但是依赖了其他以scala结尾的文件中的类的Scala Script，建议前两种方法。\n+ 在sbt中可以使用runMain，并附带命令行参数\n+ 在sbt中可以使用`set scalaVersion := \"2.11.8\"`，临时切换Scala版本\n\n### Using SBT in Chapter 7\n``` bash\n$ cd UsingTraits\n$ sbt\nsbt:usingtraits\u003e compile\n[success] Total time: 1 s, completed 2018-2-25 15:54:03\nsbt:usingtraits\u003e console\n[info] Starting scala interpreter...\nWelcome to Scala 2.12.4 (OpenJDK 64-Bit Server VM, Java 1.8.0_141).\nType in expressions for evaluation. Or try :help.\n\nscala\u003e :load UseCat.sc\nLoading UseCat.sc...\nuseFriend: (friend: Friend)Unit\nalf: Cat = Cat@24355401\nUseCat.sc:12: error: type mismatch;\n found   : Cat\n required: Friend\nval friend: Friend = alf // ERROR\n                     ^\nUseCat.sc:14: error: type mismatch;\n found   : Cat\n required: Friend\nuseFriend(alf) // ERROR\n          ^\n\nscala\u003e :load TreatCat\nwarning: File `TreatCat' does not exist.\n\nscala\u003e :load TreatCatAsFriend.sc\nLoading TreatCatAsFriend.sc...\nuseFriend: (friend: Friend)Unit\nangel: Cat with Friend = $anon$1@4e462fbb\nfriend: Friend = $anon$1@4e462fbb\nYour friend Angel is listening\nYour friend Angel is listening\n```\n\n### Using scala in Chapter 10\n``` bash\n$ cd ExceptionHandling\n$ scala -i Tax.scala \nLoading Tax.scala...\ndefined object Tax\n\nWelcome to Scala 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_141).\nType in expressions for evaluation. Or try :help.\n\nscala\u003e :load ExceptionHandling.sc\nLoading ExceptionHandling.sc...\nAmount: $100.0 Tax: $8.0\nAmount: $0.009 Don't bother reporting...Amount too small to be taxed\nAmount: $-2.0 Amount must be greater than zero\nAmount: $1000001.0 java.lang.Exception: Amount too large...\n  at Tax$.taxFor(\u003cconsole\u003e:19)\n  at $anonfun$1.apply$mcVD$sp(\u003cconsole\u003e:16)\n  at $anonfun$1.apply(\u003cconsole\u003e:13)\n  at $anonfun$1.apply(\u003cconsole\u003e:13)\n  at scala.collection.immutable.List.foreach(List.scala:381)\n  ... 65 elided\n\nscala\u003e :load CatchAll.sc\nLoading CatchAll.sc...\nAmount: $100.0 Tax: $8.0\nAmount: $0.009 Something went wrong\nAmount: $-2.0 Amount must be greater than zero\nAmount: $1000001.0 Something went wrong\n\nscala\u003e :load CatchOrder.sc\nLoading CatchOrder.sc...\namount: Int = -2\nAmount: $-2 Something went wrong\n\nscala\u003e \n```\n\n### Using sbt in Chapter 13\n``` bash\n$ cd ProgrammingActors\n$ sbt \"runMain CountFiles .\"\n[info] Packaging /home/sadhen/bitbucket/note/PragmaticScala.tm/ProgrammingActors/target/scala-2.12/programmingactors_2.12-0.1.0-SNAPSHOT.jar ...\n[info] Done packaging.\n[info] Running CountFiles .\nFiles count: 130\nTime taken: 0.098305576 seconds\n```\n","funding_links":[],"categories":["Scala"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FReactivePlatform%2FPragmatic-Scala","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FReactivePlatform%2FPragmatic-Scala","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FReactivePlatform%2FPragmatic-Scala/lists"}