Scala Documentation

repository·main·Indexed 20 days ago

https://github.com/scala/docs.scala-lang

Source code and content for the official Scala documentation website and Scala Improvement Process (SIP) documents. Built with Jekyll, the repository includes guides on Scala language features such as annotations, singleton objects, and parallel collections architecture (Splitters and Combiners), as well as getting started instructions for sbt, IntelliJ IDEA, and VSCode with Metals.

Tokens
230K
Snippets
774
Records
1K
Agent score
63%

What's inside scala-docs.scala-lang

  1. Overview of Scala 3 major changes

    main

    Scala 3 is a complete overhaul of the language designed to make the type system more principled and less intrusive. Key areas of improvement include:

    • Syntax: Introduction of 'quiet' control structures (if, while, for), optional new keyword for creator applications, optional braces with indentation-sensitive styling, and a change of type-level wildcards from _ to ?.
    • Contextual Abstractions: A shift from a single 'implicits' mechanism to multiple tailored features like using clauses, given instances, extension methods, and context functions.
    • Type System: New capabilities including Enums, Opaque Types, Intersection/Union types, Dependent/Polymorphic function types, Type lambdas, and Match types.
    • Object-Oriented Programming: Enhanced traits (parameters), open classes, transparent traits, and export clauses.
    • Metaprogramming: A robust suite of tools including inline, scala.compiletime, quasi-quotation, and a Reflection API.
  2. Overview of the Scala Toolkit

    main

    The Scala Toolkit is a collection of libraries designed to handle common programming tasks. It is cross-platform, supporting Scala 2 and Scala 3 across the JVM, Scala.js, and Scala Native.

    Common use cases include:

    • Short-lived JVM programs (web scraping, data collection/transformation, file processing).
    • Frontend browser scripts for websites.
    • Command-line tools packaged as native binaries.
  3. Review of functional error handling patterns

    main

    Functional error handling in Scala follows these core principles:

    • Avoid null: Use Option classes to represent optionality.
    • Avoid throwing exceptions: Instead of throwing exceptions, return values that encapsulate the error state, such as Option, Try, or Either.
    • Handle values explicitly: Use match expressions or for expressions to work with Option values.
    • Mental model: Think of an Option as a container that holds either exactly one item (Some) or no items (None).
  4. Summary of behavior organization patterns in Scala

    main

    When modeling domain behavior in Scala, you can choose from several organizational patterns depending on your needs:

    PatternDescription
    Companion ObjectsDefining functions in the object that shares the same name as the class.
    Modular ApproachSeparating behavior into a trait (interface) and a concrete object (implementation).
    Functional ObjectsDefining pure methods directly inside the case class that return copies of the data.
    Extension MethodsUsing extension (Scala 3) or implicit class (Scala 2) to add methods to a type externally.
  5. Where to find Scala documentation

    main

    Documentation availability varies by component:

    • Scala Library: Standard library documentation is typically found in inline comments. The Collections framework has specific architecture and guides (Synchronous, Parallel).
    • Scala Compiler: Internal documentation is scarce. Key resources include:
      • Reflection documentation: Covers Trees, Symbols, and Types.
      • Scala Compiler Corner: Covers post-typer/backend phases.
      • Scala Contributors Forum: For core design discussions.
    • Other Projects (e.g., Scaladoc): Best approached by exploring the codebase directly or contacting maintainers.
  6. Implementation status of Literal-based singleton types

    main

    Literal types have been implemented in the following environments:

    • Typelevel Scala: Used in various projects to provide better ergonomics than macro-based approaches.
    • Dotty (Scala 3): Fully supported as part of the language evolution.
    • Lightbend Scala (2.13.x): A full implementation exists as a pull request relative to the 2.13.x branch.
  7. High-level features of Scala

    main

    Scala is a high-level, statically-typed programming language that supports both Functional Programming (FP) and Object-Oriented Programming (OOP). Key characteristics include:

    • Concise Syntax: Readable and expressive code.
    • Type System: An expressive, static type system with powerful inference that provides a 'dynamic feel'.
    • FP/OOP Fusion: Uses functions for logic and objects for modularity.
    • Term Inference: Implemented via contextual abstractions.
    • Platform Support: Runs on the JVM (Java Virtual Machine), in the browser via Scala.js, and can produce native executables via Scala Native or GraalVM.
    • Java Interoperability: Seamlessly interacts with existing Java libraries and classes.
  8. Summary of Opaque Types characteristics

    main

    Opaque types are a lightweight way to add type safety to existing types (like String or Int) without the performance penalties of value classes.

    Key features:

    • Encapsulation: They are a subset of type aliases that are transparent only within the type's companion object.
    • Extensibility: Users can define their own extension methods for the opaque type.
    • Performance: Designed for performance-sensitive code; they avoid boxing/unboxing by design because they erase to the underlying type.
    • Zero Cost: They provide compile-time wrapper types with no inherent runtime footprint.
  9. Explore the Scala ecosystem and libraries

    main

    Scala features a vast ecosystem of libraries and frameworks across various domains. You can find hundreds of open-source projects in the Awesome Scala list or search the Scaladex index.

    Web Development

    • Frameworks: Play Framework (stateless, scalable), Scalatra (async, high-performance), Finatra (services built for X).
    • Frontend: Scala.js (strongly-typed JavaScript replacement) and ScalaJs-React.
    • HTTP(S) Libraries: Akka-http, Finch, Http4s, Sttp.
    • JSON Libraries: Argonaut, Circe, Json4s, Play-JSON.
    • Serialization: ScalaPB.

    Data Science, Big Data, and AI

    • Science/Analysis: Algebird, Spire, Squants.
    • Big Data: Apache Spark, Apache Flink.
    • AI/ML: BigDL (Distributed Deep Learning for Spark), TensorFlow Scala.

    Functional Programming (FP & FRP)

    • FP: Cats, Zio.
    • FRP: fs2, monix.

    Build Tools

    • sbt, Gradle, Mill.
  10. Review Scala 3 (Dotty) feature changes and language evolution

    main

    This document contains minutes from a Scala Improvement Proposal (SIP) meeting held on March 11, 2020. It outlines the committee's discussions regarding the transition from Scala 2 to Scala 3 (Dotty), including planned feature removals, new syntax, and language stability expectations.

    Key Language Evolution Notes:

    • Release Strategy: The goal was a Scala 3 release in late 2020, with TASTy stability expected in version 3.1 rather than 3.0.
    • Pattern Bindings: The case keyword is required whenever a pattern is refutable (e.g., for (case Foo(a, b) <- ...)).
    • Wildcard Types: The _ syntax is replaced by ? for wildcard types.
    • Eta Expansion: The _ syntax for eta expansion is removed.
    • Type Projection: Type projection over abstract types is considered unsound. In Scala 3.1 (under -strict), this becomes a compile error. Users may need to migrate to -Xsource:3.1.
    • Opaque Type Aliases: These provide the runtime characteristics of type aliases and are intended as an alternative to certain use cases of value classes, though they are not a direct replacement.
    • Enums: The design includes disallowing the extension of java.lang.Enum outside of enum definitions.
  11. Core benefits of Scala 3

    main

    Scala 3 is a statically typed language that provides a fusion of functional programming (FP) and object-oriented programming (OOP). Key advantages include:

    • FP/OOP Fusion: Uses functions for logic and objects for modularity.
    • Expressive Syntax: Concise and readable syntax that feels dynamic due to strong type inference.
    • Improved Implicits: Simplified and more consistent mechanism for contextual abstraction (using given and using).
    • Java Interoperability: Seamless integration with existing Java libraries and types (e.g., String, java.time).
    • Multi-platform: Runs on the server, in the browser (via Scala.js), and as native binaries (via Scala Native).
    • Rich Standard Library: Extensive collection of functional methods to reduce the need for manual loops.