[{"data":1,"prerenderedAt":741},["ShallowReactive",2],{"page-\u002Fscala":3},{"id":4,"title":5,"body":6,"description":733,"extension":734,"meta":735,"navigation":736,"path":737,"seo":738,"stem":739,"__hash__":740},"content\u002Fscala\u002Findex.md","Learn Scala — From Toolchain to Production",{"type":7,"value":8,"toc":713},"minimark",[9,14,18,21,26,77,81,121,125,130,247,251,318,322,371,375,421,425,429,454,458,490,494,517,521,540,544],[10,11,13],"h1",{"id":12},"learn-scala-from-toolchain-to-production","📖 Learn Scala — From Toolchain to Production",[15,16,17],"p",{},"A code-first engineering reference for Scala 3. Every chapter is structured around annotated production code — anti-patterns, edge cases, compiler internals, and JVM-level reality. No tutorial fluff.",[15,19,20],{},"Scala is a statically-typed, JVM-compiled language blending object-oriented and functional programming. Used in data engineering (Spark, Kafka), distributed systems (Akka, ZIO), and backend services (Twitter, LinkedIn, Databricks). This curriculum targets Scala 3.x with notes on Scala 2 interop.",[22,23,25],"h2",{"id":24},"how-to-use-this-reference","How to Use This Reference",[27,28,29,37,43,58,71],"ol",{},[30,31,32,36],"li",{},[33,34,35],"strong",{},"Read sequentially"," (01 → 11) for a structured progression from toolchain to production interop.",[30,38,39,42],{},[33,40,41],{},"Jump to a chapter"," when you hit a concept in the wild — each is self-contained.",[30,44,45,48,49,53,54,57],{},[33,46,47],{},"Run examples"," with ",[50,51,52],"code",{},"scala-cli"," (single files) or ",[50,55,56],{},"sbt"," (multi-module projects).",[30,59,60,48,63,66,67,70],{},[33,61,62],{},"Debug type errors",[50,64,65],{},"-Xprint:typer"," and ",[50,68,69],{},"-explain"," — see 01 for compiler introspection.",[30,72,73,76],{},[33,74,75],{},"Every code block is annotated"," — inline comments explain under-the-hood behavior, allocation, and bytecode mapping.",[22,78,80],{"id":79},"prerequisites","Prerequisites",[82,83,84,94,105,115,118],"ul",{},[30,85,86,89,90,93],{},[33,87,88],{},"Java 17+"," installed (",[50,91,92],{},"java -version",").",[30,95,96,97,100,101,104],{},"Scala 3 via Coursier: ",[50,98,99],{},"cs install scala3"," (preferred) or ",[50,102,103],{},"brew install scala3",".",[30,106,107,108,111,112,104],{},"sbt: ",[50,109,110],{},"brew install sbt"," or ",[50,113,114],{},"cs install sbt",[30,116,117],{},"IntelliJ IDEA with Scala plugin or VS Code with Metals.",[30,119,120],{},"Comfort with JVM concepts (classloaders, bytecode, garbage collection) and functional programming basics.",[22,122,124],{"id":123},"curriculum","Curriculum",[126,127,129],"h3",{"id":128},"part-i-foundations-execution-model","Part I — Foundations & Execution Model",[131,132,133,149],"table",{},[134,135,136],"thead",{},[137,138,139,143,146],"tr",{},[140,141,142],"th",{},"#",[140,144,145],{},"Topic",[140,147,148],{},"Why It Matters",[150,151,152,168,199,223],"tbody",{},[137,153,154,158,165],{},[155,156,157],"td",{},"01",[155,159,160],{},[161,162,164],"a",{"href":163},"\u002Fscala\u002F01-getting-started","Toolchain & JVM Execution Model",[155,166,167],{},"Compiler phases, bytecode mapping, sbt\u002Fscala-cli, project layout. Without this, you can't debug type errors or perf.",[137,169,170,173,179],{},[155,171,172],{},"02",[155,174,175],{},[161,176,178],{"href":177},"\u002Fscala\u002F02-variables-and-data-types","Value Semantics & Type Hierarchy",[155,180,181,184,185,184,188,191,192,184,195,198],{},[50,182,183],{},"val","\u002F",[50,186,187],{},"var",[50,189,190],{},"lazy val"," init semantics, primitive boxing, opaque types, ",[50,193,194],{},"AnyVal",[50,196,197],{},"AnyRef",", IEEE 754 gotchas.",[137,200,201,204,210],{},[155,202,203],{},"03",[155,205,206],{},[161,207,209],{"href":208},"\u002Fscala\u002F03-functions","Functions & Closures",[155,211,212,215,216,219,220,104],{},[50,213,214],{},"Function1"," JVM representation, closure capture, ",[50,217,218],{},"@tailrec",", by-name vs by-need, currying, ",[50,221,222],{},"inline def",[137,224,225,228,234],{},[155,226,227],{},"04",[155,229,230],{},[161,231,233],{"href":232},"\u002Fscala\u002F04-control-flow","Pattern Matching & Exhaustiveness",[155,235,236,237,184,240,184,243,246],{},"Sealed exhaustiveness, type erasure traps, custom extractors, match types, ",[50,238,239],{},"Either",[50,241,242],{},"Try",[50,244,245],{},"Option"," as error values.",[126,248,250],{"id":249},"part-ii-collections-object-model","Part II — Collections & Object Model",[131,252,253,263],{},[134,254,255],{},[137,256,257,259,261],{},[140,258,142],{},[140,260,145],{},[140,262,148],{},[150,264,265,279,300],{},[137,266,267,270,276],{},[155,268,269],{},"05",[155,271,272],{},[161,273,275],{"href":274},"\u002Fscala\u002F05-collections","Collections: Persistent Data Structures",[155,277,278],{},"Vector RRB-trees, structural sharing, lazy views, fusion, performance characteristics, streaming patterns.",[137,280,281,284,290],{},[155,282,283],{},"06",[155,285,286],{},[161,287,289],{"href":288},"\u002Fscala\u002F06-classes-and-objects","Classes, Traits & Object Model",[155,291,292,293,184,296,299],{},"Trait linearization, self types, ",[50,294,295],{},"open",[50,297,298],{},"sealed",", universal equality, companion objects, path-dependent types.",[137,301,302,305,311],{},[155,303,304],{},"07",[155,306,307],{},[161,308,310],{"href":309},"\u002Fscala\u002F07-case-classes-and-pattern-matching","Case Classes & ADTs",[155,312,313,314,317],{},"Generated code, ADT design, recursive types, regex patterns, custom extractors, ",[50,315,316],{},"copy"," and lens patterns.",[126,319,321],{"id":320},"part-iii-type-system-concurrency","Part III — Type System & Concurrency",[131,323,324,334],{},[134,325,326],{},[137,327,328,330,332],{},[140,329,142],{},[140,331,145],{},[140,333,148],{},[150,335,336,350],{},[137,337,338,341,347],{},[155,339,340],{},"08",[155,342,343],{},[161,344,346],{"href":345},"\u002Fscala\u002F08-type-system","Type System: Variance & Phantom Types",[155,348,349],{},"Variance constraints, type classes (given\u002Fusing), higher-kinded types, phantom types for state machines, match types.",[137,351,352,355,361],{},[155,353,354],{},"09",[155,356,357],{},[161,358,360],{"href":359},"\u002Fscala\u002F09-concurrent-programming","Concurrency: Futures & Backpressure",[155,362,363,364,367,368,370],{},"ExecutionContext tuning, parallel vs sequential, retry with backoff, race conditions, ",[50,365,366],{},"Promise",", ",[50,369,242],{},", atomic operations.",[126,372,374],{"id":373},"part-iv-production","Part IV — Production",[131,376,377,387],{},[134,378,379],{},[137,380,381,383,385],{},[140,382,142],{},[140,384,145],{},[140,386,148],{},[150,388,389,403],{},[137,390,391,394,400],{},[155,392,393],{},"10",[155,395,396],{},[161,397,399],{"href":398},"\u002Fscala\u002F10-testing","Testing: ScalaTest & ScalaCheck",[155,401,402],{},"Fixtures, property-based testing with shrinking, mock-free design with fakes, tagged integration tests, async testing.",[137,404,405,408,414],{},[155,406,407],{},"11",[155,409,410],{},[161,411,413],{"href":412},"\u002Fscala\u002F11-java-interoperability","Java Interoperability",[155,415,416,417,420],{},"Collection views vs copies, null safety bridges, SAM conversion, ",[50,418,419],{},"@targetName",", Java-friendly API design, boxing overhead.",[22,422,424],{"id":423},"learning-path-suggestions","Learning Path Suggestions",[126,426,428],{"id":427},"if-youre-coming-from-java","If you're coming from Java",[27,430,431,437,445,448,451],{},[30,432,433,434,104],{},"Read 01 closely — the compiler pipeline and bytecode mapping differ from ",[50,435,436],{},"javac",[30,438,439,440,184,442,444],{},"Skim 02–03 — ",[50,441,183],{},[50,443,187],{}," and lambdas map to Java concepts but with different init semantics.",[30,446,447],{},"Read 04 & 07 — sealed exhaustiveness and pattern matching are Scala's biggest wins over Java.",[30,449,450],{},"Read 08 — variance, type classes, and phantom types are concepts Java doesn't have.",[30,452,453],{},"Read 11 — interop has subtle traps (views vs copies, boxing, checked exceptions).",[126,455,457],{"id":456},"if-youre-coming-from-pythonruby","If you're coming from Python\u002FRuby",[27,459,460,467,470,473,476],{},[30,461,462,463,466],{},"Read 02 — static types, type inference, and the ",[50,464,465],{},"Any"," hierarchy are fundamentally different.",[30,468,469],{},"Read 03–04 — closures, tail recursion, and pattern matching replace dynamic dispatch.",[30,471,472],{},"Read 05 — persistent data structures and structural sharing replace mutable defaults.",[30,474,475],{},"Read 08 — the type system (variance, type classes) is the biggest paradigm shift.",[30,477,478,479,66,482,485,486,489],{},"Read 09 — ",[50,480,481],{},"Future",[50,483,484],{},"ExecutionContext"," replace ",[50,487,488],{},"asyncio"," with a thread-pool model.",[126,491,493],{"id":492},"if-youre-coming-from-haskellocaml","If you're coming from Haskell\u002FOCaml",[27,495,496,499,502,505,514],{},[30,497,498],{},"Skim 01–05 — most concepts are familiar; focus on JVM-specific details (boxing, erasure).",[30,500,501],{},"Read 07 — ADTs and pattern matching are similar but with different ergonomics.",[30,503,504],{},"Read 08 closely — variance annotations and type classes (given\u002Fusing) differ from typeclass instances.",[30,506,478,507,509,510,513],{},[50,508,481],{}," is eager (not lazy like ",[50,511,512],{},"IO","); consider ZIO or Cats Effect for laziness.",[30,515,516],{},"Read 11 — Java interop is unique to Scala and has real production consequences.",[126,518,520],{"id":519},"if-youre-a-senior-engineer-using-scala-in-production","If you're a senior engineer using Scala in production",[27,522,523,526,529,534,537],{},[30,524,525],{},"Read 01 — compiler phases and bytecode mapping for debugging production issues.",[30,527,528],{},"Read 05 & 08 — collection performance and type system design for API\u002Flibrary design.",[30,530,478,531,533],{},[50,532,484],{}," tuning and backpressure for high-throughput services.",[30,535,536],{},"Read 10 — property-based testing and mock-free design for maintainable test suites.",[30,538,539],{},"Use 11 as a reference for cross-language team boundaries.",[22,541,543],{"id":542},"key-differences-from-java-quick-reference","Key Differences from Java (Quick Reference)",[131,545,546,556],{},[134,547,548],{},[137,549,550,553],{},[140,551,552],{},"Java",[140,554,555],{},"Scala 3",[150,557,558,570,587,607,621,633,647,664,678,698],{},[137,559,560,565],{},[155,561,562],{},[50,563,564],{},"public static void main(String[] args)",[155,566,567],{},[50,568,569],{},"@main def run(): Unit = ...",[137,571,572,577],{},[155,573,574],{},[50,575,576],{},"int x = 5;",[155,578,579,582,583,586],{},[50,580,581],{},"val x = 5"," (immutable) or ",[50,584,585],{},"var x = 5"," (mutable)",[137,588,589,594],{},[155,590,591],{},[50,592,593],{},"Optional\u003CT>",[155,595,596,599,600,603,604],{},[50,597,598],{},"Option[T]"," — ",[50,601,602],{},"Some(v)"," \u002F ",[50,605,606],{},"None",[137,608,609,615],{},[155,610,611,614],{},[50,612,613],{},"switch"," (fallthrough, no exhaustiveness)",[155,616,617,620],{},[50,618,619],{},"match"," — expression, exhaustiveness-checked on sealed",[137,622,623,626],{},[155,624,625],{},"Checked exceptions",[155,627,628,629,184,631],{},"No checked exceptions — use ",[50,630,242],{},[50,632,239],{},[137,634,635,641],{},[155,636,637,640],{},[50,638,639],{},"instanceof"," + cast",[155,642,643,644],{},"Pattern match: ",[50,645,646],{},"case s: String => ...",[137,648,649,655],{},[155,650,651,654],{},[50,652,653],{},"ArrayList\u003CT>"," (mutable, covariant arrays)",[155,656,657,660,661],{},[50,658,659],{},"Vector[T]"," (immutable, persistent) or ",[50,662,663],{},"ArrayBuffer[T]",[137,665,666,672],{},[155,667,668,671],{},[50,669,670],{},"Function\u003CT,R>"," (single interface)",[155,673,674,677],{},[50,675,676],{},"T => R"," (Function1, with 22 arities + specialized variants)",[137,679,680,686],{},[155,681,682,685],{},[50,683,684],{},"synchronized"," blocks",[155,687,688,690,691,690,694,690,696],{},[50,689,684],{}," + ",[50,692,693],{},"AtomicLong",[50,695,481],{},[50,697,366],{},[137,699,700,703],{},[155,701,702],{},"Getter\u002Fsetter conventions",[155,704,705,706,184,709,712],{},"Properties (direct field access, no ",[50,707,708],{},"getX()",[50,710,711],{},"setX()",")",{"title":714,"searchDepth":715,"depth":715,"links":716},"",2,[717,718,719,726,732],{"id":24,"depth":715,"text":25},{"id":79,"depth":715,"text":80},{"id":123,"depth":715,"text":124,"children":720},[721,723,724,725],{"id":128,"depth":722,"text":129},3,{"id":249,"depth":722,"text":250},{"id":320,"depth":722,"text":321},{"id":373,"depth":722,"text":374},{"id":423,"depth":715,"text":424,"children":727},[728,729,730,731],{"id":427,"depth":722,"text":428},{"id":456,"depth":722,"text":457},{"id":492,"depth":722,"text":493},{"id":519,"depth":722,"text":520},{"id":542,"depth":715,"text":543},"A rigorous, code-first Scala 3 engineering reference covering the JVM execution model, persistent data structures, type-level programming, concurrency, and production interop. Built for mid-to-senior developers.","md",{},true,"\u002Fscala",{"title":5,"description":733},"scala\u002Findex","7sDsXUdqnEwJxOnukPvuY_AcokbxZUaRmMmX8Y_zZms",1789924654199]