Beginning Scala 3 - A Functional and Object-Oriented Java Language (3rd Edition)
Learn the latest version of Scala through simple, practical examples. This book introduces you to the Scala programming language, its object-oriented and functional programming characteristics, and then guides you through Scala constructs and libraries that allow you to assemble small components int...
Uloženo v:
| Hlavní autor: | |
|---|---|
| Médium: | E-kniha |
| Jazyk: | angličtina |
| Vydáno: |
Berkeley, CA
Apress, an imprint of Springer Nature
2022
Apress Apress L. P |
| Vydání: | 3 |
| Témata: | |
| ISBN: | 9781484274217, 1484274210, 9781484274224, 1484274229 |
| On-line přístup: | Získat plný text |
| Tagy: |
Přidat tag
Žádné tagy, Buďte první, kdo vytvoří štítek k tomuto záznamu!
|
Obsah:
- Title Page Introduction Table of Contents 1. Getting Started with Scala 2. Basics of Scala 3. Object-Oriented Modeling 4. Functional Programming 5. Pattern Matching 6. Scala Collections 7. Traits and Enums 8. Scala Type System 9. Scala and Java Interoperability 10. DSL and Parser Combinator 11. Simple Build Tool 12. Creating Web Applications 13. Testing Your Code 14. Scala Best Practices Index
- Chapter 14: Scala Best Practices -- General Best Practices -- Recognizing the Functional Style -- Writing Pure Functions -- Leveraging Type Inferencing -- Think Expressions -- Focusing on Immutability -- Keeping Methods Short -- Using Options Instead of Null Testing -- Refactor Mercilessly -- Composing Functions and Classes -- Summary -- Index
- Intro -- Table of Contents -- About the Authors -- About the Technical Reviewer -- Acknowledgments -- Introduction -- Chapter 1: Getting Started with Scala -- Why Use Scala? -- Migrating to Scala 3 -- History -- Installing Scala Tools -- Installing Java JDK -- Installing Scala -- Using Brew -- Using Coursier -- Installing SBT -- Installing the IDE -- Running Code Examples -- Using an IDE -- Manually Using the REPL -- Running Little Blocks -- Compiling and Running Files -- Online Tools -- Summary -- Chapter 2: Basics of Scala -- Variables -- Scala Type Hierarchy -- Any, AnyVal, and AnyRef Types -- Numeric Types -- Types and Range -- Conversion -- Format -- Boolean -- Char -- Unit -- Strings -- Interpolation -- Compare -- Split -- Replace -- Special Characters -- Other Methods -- Date -- Format -- Arrays -- Lists -- Null -- Nothing -- Functions -- Control Structures -- if/then/else Expressions -- for Loops -- while Loops -- match Expressions -- try/catch/finally Blocks -- Comments -- Running Code Without the REPL -- Keywords -- Summary -- Chapter 3: Object-Oriented Modeling -- Concepts of OOP -- From Concepts to Concrete Things -- Classes -- Fields -- Constructors -- Visibility of the Fields -- Auxiliary Constructors -- Providing Default Values -- Private Constructor -- Methods -- Order -- Invoking Methods -- Override Default Methods -- toString -- equals -- Inheritance -- Inner Classes -- Value Classes -- Packages and Imports -- Multiple Imports -- Exclude Class -- Objects -- Defining Singletons -- Companion Objects -- Static Factory -- Opaque Types -- Export Clauses -- Summary -- Chapter 4: Functional Programming -- What Is Functional Programming? -- Pure Functions -- Side Effects -- Referential Transparency -- Expression-Oriented Programming -- Functions, Lambdas, and Closures -- Function Literal/Anonymous Function
- First-Class Functions and Higher-Order Functions -- Functions as Variables -- Functions as Parameters -- Returning a Function -- Closure -- Partially Applied Functions -- Curried Functions -- Function Compositions -- Function Error Handling -- Tail Calls and Tail Call Optimization -- Call-by-Name, Call-by-Value, and General Laziness -- Functional Structures -- Sequence -- Maps -- Sets -- Tuples -- Options -- Instantiating -- Chained Methods -- Functional Operations -- Traversing -- Mapping -- Filtering -- Summary -- Chapter 5: Pattern Matching -- Basic Pattern Matching -- Matching Any Type -- Testing Data Types -- Pattern Matching in Lists -- Pattern Matching and Lists -- Compiler Optimization -- Tableswitch -- Lookupswitch -- Considerations -- Pattern Matching with the Matchable Trait -- Pattern Matching and Case Classes -- Nested Pattern Matching in Case Classes -- Pattern Matching as Functions -- Pattern Matching on Regular Expressions -- Object-Oriented and Functional Tensions -- Shape Abstractions -- Summary -- Chapter 6: Scala Collections -- Scala Collection Hierarchy -- The scala.collection Package -- Sequences -- Sets -- Map -- The scala.collection.immutable package -- Immutable Sequence -- Immutable Set -- Immutable Map -- The scala.collection.mutable package -- Using Immutable Collection Classes -- Vector -- List[T] -- Getting Functional -- Transformation -- Reduxio -- Look Ma, No Loops -- Range -- Stream or LazyList -- Tuples -- Map[K, V] -- Mutable Collections -- Mutable ArrayBuffer -- Mutable Queue -- Mutable Stack -- Performance of the Collections -- Summary -- Chapter 7: Traits and Enums -- Traits -- Using Traits as Mixins -- Traits and Class Hierarchies -- Conflicts of Method Names -- Limiting the Use of a Trait -- Limiting Access by Class -- Limiting Access by Method -- Type Parameters or Type Members -- Passing Parameters on Traits
- Enumerations -- Algebraic Data Types in Enums -- Union and Intersection Types -- Summary -- Chapter 8: Scala Type System -- Unified Type System -- Type Parameterization -- Variance -- Covariant Parameter Types -- Contravariant Parameter Types -- Invariant Parameter Types -- Rules of Variance -- Type Bounds -- Upper Type Bounds -- Lower Type Bounds -- Extension Methods -- Scala 2 Implicit Class -- Scala 3 Given/Using Clauses -- Implicit Conversions -- Givens and Imports -- Using Clauses -- Summary -- Chapter 9: Scala and Java Interoperability -- Scala at a Glance -- Translating Java Classes to Scala Classes -- Translating Java Imports into Scala Imports -- Translating Multiple Constructors -- JavaBean Specification-Compliant Scala Classes -- Java Interfaces and Scala Traits -- Java Static Members and Scala Objects -- Handling Exceptions -- Java Optional and Scala Option -- Use Java Collections in Scala -- Summary -- Chapter 10: DSL and Parser Combinator -- A Closer Look at DSLs -- Internal DSLs -- External DSLs -- Summary -- Chapter 11: Simple Build Tool -- Getting Started with SBT -- Why SBT? -- Installing SBT -- General Commands -- Creating a Hello World Project -- Project Structure -- build.sbt -- Project Folder -- Src Folder -- Build Definition -- LibraryDependencies and Resolvers -- Plugins -- Summary -- Chapter 12: Creating Web Applications -- Architecture Types -- Setting Up the Application -- Application Flow -- Router -- Controller -- Model -- View -- Rest Application -- Defining the Endpoints -- Layers in the Application -- Custom Error Handler -- Summary -- Chapter 13: Testing Your Code -- Testing with ScalaTest -- Writing Your First Test -- Ignoring the Execution of the Test -- Other Ways of Declaring the Test -- Using Matchers to Validate Results -- Tagging Your Test -- Before and After Methods -- Summary

