My Account Log in

1 option

Scala cookbook / Alvin Alexander.

O'Reilly Online Learning: Academic/Public Library Edition Available online

View online
Format:
Book
Author/Creator:
Alexander, Alvin, author.
Language:
English
Subjects (All):
Scala (Computer program language).
Programming languages (Electronic computers).
Physical Description:
1 online resource (700 pages)
Edition:
Second edition.
Place of Publication:
Sebastopol, California : O'Reilly Media, Incorporated, [2021]
System Details:
text file
Summary:
Save time and trouble building object-oriented, functional, and concurrent applications with Scala 3. The latest edition of this comprehensive cookbook is packed with more than 250 ready-to-use recipes and 700 code examples to help you solve the most common problems when working with Scala and its popular libraries. Whether you’re working on web, big data, or distributed applications, this cookbook provides recipes based on real-world scenarios for experienced Scala developers and for programmers just learning to use this JVM language. Author Alvin Alexander includes practical solutions from his experience using Scala for highly scalable applications that support concurrency and distribution. Recipes cover: Strings, numbers, and control structures Classes, methods, objects, traits, packaging, and imports Functional programming in a variety of situations Building Scala applications with sbt Collections covering Scala’s wealth of classes and methods Actors and concurrency List, array, map, set, and more Files, processes, and command-line tasks Web services and interacting with Java Databases and persistence, data types and idioms
Contents:
Intro
Copyright
Table of Contents
Preface
Conventions Used in This Book
Using Code Examples
O'Reilly Online Learning
How to Contact Us
Acknowledgments
Chapter 1. Command-Line Tasks
1.1 Getting Started with the Scala REPL
Problem
Solution
Discussion
See Also
1.2 Loading Source Code and JAR Files into the REPL
1.3 Getting Started with the Ammonite REPL
1.4 Compiling with scalac and Running with scala
1.5 Disassembling and Decompiling Scala Code
1.6 Running JAR Files with Scala and Java
Chapter 2. Strings
2.1 Testing String Equality
2.2 Creating Multiline Strings
2.3 Splitting Strings
2.4 Substituting Variables into Strings
2.5 Formatting String Output
2.6 Processing a String One Character at a Time
A Complete Example
2.7 Finding Patterns in Strings
2.8 Replacing Patterns in Strings
2.9 Extracting Parts of a String That Match Patterns
2.10 Accessing a Character in a String
2.11 Creating Your Own String Interpolator
2.12 Creating Random Strings
Chapter 3. Numbers and Dates
3.1 Parsing a Number from a String.
Problem
3.2 Converting Between Numeric Types (Casting)
3.3 Overriding the Default Numeric Type
3.4 Replacements for ++ and −−
3.5 Comparing Floating-Point Numbers
3.6 Handling Large Numbers
3.7 Generating Random Numbers
3.8 Formatting Numbers and Currency
Locales
3.9 Creating New Date and Time Instances
3.10 Calculating the Difference Between Two Dates
3.11 Formatting Dates
3.12 Parsing Strings into Dates
Chapter 4. Control Structures
for Loops and for Expressions
if/then/else-if Expressions
match Expressions and Pattern Matching
try/catch/finally Blocks
while Loops
Control Structures as a Defining Feature of Programming Languages
4.1 Looping over Data Structures with for
4.2 Using for Loops with Multiple Counters
4.3 Using a for Loop with Embedded if Statements (Guards)
4.4 Creating a New Collection from an Existing Collection with for/yield
4.5 Using the if Construct Like a Ternary Operator
4.6 Using a Match Expression Like a switch Statement
4.7 Matching Multiple Conditions with One Case Statement
See Also.
4.8 Assigning the Result of a Match Expression to a Variable
4.9 Accessing the Value of the Default Case in a Match Expression
4.10 Using Pattern Matching in Match Expressions
4.11 Using Enums and Case Classes in match Expressions
4.12 Adding if Expressions (Guards) to Case Statements
4.13 Using a Match Expression Instead of isInstanceOf
4.14 Working with a List in a Match Expression
4.15 Matching One or More Exceptions with try/catch
4.16 Declaring a Variable Before Using It in a try/catch/finally Block
4.17 Creating Your Own Control Structures
Chapter 5. Classes
Classes and Case Classes
5.1 Choosing from Domain Modeling Options
5.2 Creating a Primary Constructor
5.3 Controlling the Visibility of Constructor Fields
5.4 Defining Auxiliary Constructors for Classes
5.5 Defining a Private Primary Constructor
5.6 Providing Default Values for Constructor Parameters
5.7 Handling Constructor Parameters When Extending a Class
5.8 Calling a Superclass Constructor
5.9 Defining an equals Method (Object Equality)
Discussion.
See Also
5.10 Preventing Accessor and Mutator Methods from Being Generated
5.11 Overriding Default Accessors and Mutators
5.12 Assigning a Block or Function to a (lazy) Field
5.13 Setting Uninitialized var Field Types
5.14 Generating Boilerplate Code with Case Classes
5.15 Defining Auxiliary Constructors for Case Classes
Chapter 6. Traits and Enums
6.1 Using a Trait as an Interface
6.2 Defining Abstract Fields in Traits
6.3 Using a Trait Like an Abstract Class
6.4 Using Traits as Mixins
6.5 Resolving Method Name Conflicts and Understanding super
6.6 Marking Traits So They Can Only Be Used by Subclasses of a Certain Type
6.7 Ensuring a Trait Can Only Be Added to a Type That Has a Specific Method
6.8 Limiting Which Classes Can Use a Trait by Inheritance
6.9 Working with Parameterized Traits
6.10 Using Trait Parameters
6.11 Using Traits to Create Modules
6.12 How to Create Sets of Named Values with Enums
6.13 Modeling Algebraic Data Types with Enums
Chapter 7. Objects
7.1 Casting Objects
7.2 Passing a Class Type with the classOf Method
7.3 Creating Singletons with object
7.4 Creating Static Members with Companion Objects
7.5 Using apply Methods in Objects as Constructors
7.6 Implementing a Static Factory with apply
7.7 Reifying Traits as Objects
7.8 Implementing Pattern Matching with unapply
Chapter 8. Methods
8.1 Controlling Method Scope (Access Modifiers)
8.2 Calling a Method on a Superclass or Trait
8.3 Using Parameter Names When Calling a Method
8.4 Setting Default Values for Method Parameters
8.5 Creating Methods That Take Variable-Argument Fields
8.6 Forcing Callers to Leave Parentheses Off Accessor Methods
8.7 Declaring That a Method Can Throw an Exception
8.8 Supporting a Fluent Style of Programming
8.9 Adding New Methods to Closed Classes with Extension Methods
Chapter 9. Packaging and Imports
9.1 Packaging with the Curly Braces Style Notation
9.2 Importing One or More Members
9.3 Renaming Members on Import
Solution.
Discussion.
Notes:
Description based on print version record.
Includes index.
ISBN:
1-4920-5149-7
1-4920-5151-9
1-4920-5153-5

The Penn Libraries is committed to describing library materials using current, accurate, and responsible language. If you discover outdated or inaccurate language, please fill out this feedback form to report it and suggest alternative language.

Find

Home Release notes

My Account

Shelf Request an item Bookmarks Fines and fees Settings

Guides

Using the Find catalog Using Articles+ Using your account