{"id":18996629,"url":"https://github.com/vonzhou/programminginscala","last_synced_at":"2025-09-19T18:32:45.020Z","repository":{"id":81368171,"uuid":"165077869","full_name":"vonzhou/ProgrammingInScala","owner":"vonzhou","description":"Programming In Scala 3rd Examples.《Scala编程》第三版代码","archived":false,"fork":false,"pushed_at":"2019-04-03T06:10:04.000Z","size":83,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T13:55:47.807Z","etag":null,"topics":["functional-programming","haskell","java","scala"],"latest_commit_sha":null,"homepage":"https://github.com/vonzhou/learning-scala","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vonzhou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-01-10T14:52:14.000Z","updated_at":"2020-09-28T15:38:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"4593405c-078a-4264-b13d-35455f3375d3","html_url":"https://github.com/vonzhou/ProgrammingInScala","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vonzhou/ProgrammingInScala","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vonzhou%2FProgrammingInScala","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vonzhou%2FProgrammingInScala/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vonzhou%2FProgrammingInScala/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vonzhou%2FProgrammingInScala/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vonzhou","download_url":"https://codeload.github.com/vonzhou/ProgrammingInScala/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vonzhou%2FProgrammingInScala/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275982496,"owners_count":25564149,"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","status":"online","status_checked_at":"2025-09-19T02:00:09.700Z","response_time":108,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["functional-programming","haskell","java","scala"],"created_at":"2024-11-08T17:36:09.770Z","updated_at":"2025-09-19T18:32:44.994Z","avatar_url":"https://github.com/vonzhou.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Programming In Scala\n\n脚本运行方式:\n\n```\nscala -nc hello.scala\n```\n\n\n类运行方式:\n\n```\n➜  ch04 git:(master) ✗ scalac ChecksumAccumulator.scala Summer.scala\n➜  ch04 git:(master) ✗ scala ch04.Summer hello scala                \nhello: -20\nscala: -4\n```\n\n\n## 1. A Scalable Language\n\n语言命名\n\n## 2. First Steps in Scala\n\n写点脚本\n\n## 3. Next Steps in Scala\n\n使用List,Tuple,Set,Map\n\n读文件\n\n## 4. Classes and Objects\n\n## 5. Basic Types and Operations\n\n## 6. Functional Objects\n\n## 7. Built-in Control Structures\n\n## 8. Functions and Closures\n\n## 9. Control Abstractions\n\n## 10. Composition and Inheritance\n\n## 11. Scala's Hierarchy\n\n## 12. Traits\n\n## 13. Packages and Imports\n\n## 14. Assertions and Tests\n\n## 15. Case Classes and Pattern Matching\n\n## 16. Working with Lists\n\n## 17. Working with other Collections\n\n## 18. Mutable Objects\n\n## 19. Type Parameterization\n\n## 20. Abstract Members\n\n```Scala\nscala\u003e trait Abstract {\n     |   type T\n     |\n     |   def transform(x: T): T\n     |\n     |   val initial: T\n     |\n     |   var current: T\n     | }\ndefined trait Abstract\n\nscala\u003e class Concrete extends Abstract {\n     |   type T = String\n     |\n     |   def transform(x: String) = x + x\n     |\n     |   val initial = \"hi\"\n     |   var current = initial\n     | }\ndefined class Concrete\n\nscala\u003e\n\nscala\u003e println(new Concrete().transform(\"vonzhou\"))\nvonzhouvonzhou\n```\n\n\n## 21.  Implicit Conversions and Parameters\n\nscala.Int:\n\n```scala\n  import scala.language.implicitConversions\n  implicit def int2long(x: Int): Long = x.toLong\n  implicit def int2float(x: Int): Float = x.toFloat\n  implicit def int2double(x: Int): Double = x.toDouble\n```\n\nPredef:\n\n```scala\n implicit final class ArrowAssoc[A](private val self: A) extends AnyVal {\n    @inline def -\u003e [B](y: B): Tuple2[A, B] = Tuple2(self, y)\n    def →[B](y: B): Tuple2[A, B] = -\u003e(y)\n  }\n```\n\n## 22. Implementing Lists\n\n2个子类：:: 和 Nil\n\ncovariant\n\n```scala\nval xs = List(1,2,3)\nvar ys:List[Any] = xs\nprintln(ys)\n```\n\n\nList定义了3个抽象方法：\n\n```scala\n def isEmpty: Boolean\n  def head: A\n  def tail: List[A]\n```\n\n\n:: 方法的参数类型有一个lower bound，交互模式下运行：\n\n```scala\nscala\u003e abstract class Fruit\ndefined class Fruit\n\nscala\u003e class Apple extends Fruit\ndefined class Apple\n\nscala\u003e class Orange extends Fruit\ndefined class Orange\n\nscala\u003e val apples = new Apple :: Nil\napples: List[Apple] = List(Apple@1224e1b6)\n\nscala\u003e val fruits = new Orange :: apples\nfruits: List[Fruit] = List(Orange@61d09475, Apple@1224e1b6)\n```\n\nListBuffer的实现：\n\n```scala\n  def += (x: A): this.type = {\n    if (exported) copy()\n    if (isEmpty) {\n      last0 = new :: (x, Nil)\n      start = last0\n    } else {\n      val last1 = last0\n      last0 = new :: (x, Nil)\n      // 注意 :: 类构造器参数 tl 是var\n      last1.tl = last0\n    }\n    len += 1\n    this\n  }\n```\n\n\u003e The design of Scala's List and ListBuffer is quite similar to what's done in Java's pair of classes String and StringBuffer.\n\n## 23. For Expression Revisited\n\nfor 表达式最终都会被scala 编译器转换成map, flatMap, withFilter。\n\n## 24. Collections in depth","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvonzhou%2Fprogramminginscala","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvonzhou%2Fprogramminginscala","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvonzhou%2Fprogramminginscala/lists"}