
Get Programming with Scala
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Summary
In Get Programming in Scala you will learn:
Object-oriented principles in Scala
Express program designs in functions
Use types to enforce program requirements
Use abstractions to avoid code duplication
Write meaningful tests and recognize code smells
Scala is a multi-style programming language for the JVM that supports both object-oriented and functional programming. Master Scala, and you'll be well-equipped to match your programming approach to the type of problem you're dealing with. Packed with examples and exercises, Get Programming with Scala is the perfect starting point for developers with some OO knowledge who want to learn Scala and pick up a few FP skills along the way.
Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.
About the technology
Scala developers are in high demand. This flexible language blends object-oriented and functional programming styles so you can write flexible, easy-to-maintain code. Because Scala runs on the JVM, your programs can interact seamlessly with Java libraries and tools. If you're comfortable writing Java, this easy-to-read book will get you programming with Scala fast.
About the book
Get Programming with Scala is a fast-paced introduction to the Scala language, covering both Scala 2 and Scala 3. You'll learn through lessons, quizzes, and hands-on projects that bring your new skills to life. Clear explanations make Scala's features and abstractions easy to understand. As you go, you'll learn to write familiar object-oriented code in Scala and also discover the possibilities of functional programming.
What's inside
Apply object-oriented principles in Scala
Learn the core concepts of functional programming
Use types to enforce program requirements
Use abstractions to avoid code duplication
Write meaningful tests and recognize code smells
About the reader
For developers who know an OOP language like Java, Python, or C#. No experience with Scala or functional programming required.
About the author
Daniela Sfregola is a Senior Software Engineer and a Scala user since 2013. She is an active contributor to the Scala Community, a public speaker at Scala conferences and meetups, and a maintainer of open-source projects.
Table of Contents
Unit 0 HELLO SCALA!
Unit 1 THE BASICS
Unit 2 OBJECT-ORIENTED FUNDAMENTALS
Unit 3 HTTP SERVER
Unit 4 IMMUTABLE DATA AND STRUCTURES
Unit 5 LIST
Unit 6 OTHER COLLECTIONS AND ERROR HANDLING
Unit 7 CONCURRENCY
Unit 8 JSON (DE)SERIALIZATION
More details
Person
Content
- Intro
- inside front cover
- Get Programming with Scala
- Copyright
- dedication
- Contents
- front matter
- Preface
- Acknowledgments
- About this book
- Who should read this book
- How this book is organized: A roadmap
- About the code
- liveBook discussion forum
- About the author
- Unit 0. Hello Scala!
- 1 Why Scala?
- 1.1 Why Scala?
- 1.2 Scala and the JVM
- 1.3 Scala's key features
- Summary
- 2 The Scala environment
- 2.1 The REPL installation
- 2.2 The REPL commands
- 2.3 The REPL code evaluation
- 2.4 Other development tools
- 2.4.1 Git installation
- 2.4.2 Docker installation
- Summary
- 3 Scala Build Tool (sbt)
- 3.1 Why sbt?
- 3.2 sbt installation
- 3.3 sbt commands
- 3.4 Your first sbt project
- 3.5 sbt project structure
- Summary
- Unit 1. The Basics
- 4 Values and variables
- 4.1 Values
- 4.2 Variables
- Summary
- Answers to quick checks
- 5 Conditional constructs and loops
- 5.1 If-else construct
- 5.2 While loop
- 5.3 For loop
- Summary
- Answers to quick checks
- 6 Function as the most fundamental block of code
- 6.1 Functions
- Summary
- Answers to quick checks
- 7 Classes and subclasses to represent the world
- 7.1 Class
- 7.2 Subclass
- 7.3 Abstract class
- Summary
- Answers to quick checks
- 8 The vending machine
- 8.1 Setting up the vending machine
- 8.1.1 The VendingMachine class and its APIs
- 8.1.2 The vending machine and its operations
- 8.1.3 Let's try it out
- 8.2 Possible improvements to our solution
- Summary
- Unit 2. Object-oriented fundamentals
- 9 Import and create packages
- 9.1 Import an existing package
- 9.2 Create a package
- Summary
- Answers to quick checks
- 10 Scope your code with access modifiers
- 10.1 Public, the default access modifier
- 10.2 Private
- 10.3 Protected
- 10.4 Which access level to use?
- Summary
- Answers to quick checks
- 11 Singleton objects
- 11.1 Object
- 11.2 Executable object
- 11.3 Companion object
- 11.4 The apply method
- Summary
- Answers to quick checks
- 12 Traits as interfaces
- 12.1 Defining traits
- 12.2 Extending traits
- 12.3 Sealed traits
- 12.4 Enumeration in Scala 3
- Summary
- Answers to quick checks
- 13 What time is it?
- 13.1 What time is it?
- 13.1.1 sbt project setup
- 13.1.2 The business logic layer
- 13.1.3 The TimeApp executable object
- 13.1.4 Let's try it out!
- 13.2 Possible improvements to our solution
- Summary
- Unit 3. HTTP server
- 14 Pattern matching
- 14.1 If-else construct vs. pattern matching
- 14.2 Sealed pattern matching
- Summary
- Answers to quick checks
- 15 Anonymous functions
- 15.1 Function vs. anonymous function
- 15.2 Concise notation for anonymous functions
- Summary
- Answers to quick checks
- 16 Partial functions
- 16.1 Partial functions
- 16.1.1 Implementing a partial function
- 16.1.2 Function composition
- 16.2 Use case: Exception handling
- Summary
- Answers to quick checks
- 17 HTTP API with http4s
- 17.1 An overview of http4s
- 17.2 A ping server using http4s
- 17.2.1 Initial setup
- 17.2.2 Implementing the API
- 17.2.3 Building a server
- 17.2.4 Let's try it out!
- Summary
- Answers to quick checks
- 18 The time HTTP server
- 18.1 What time is it?
- 18.1.1 Setting your sbt project up
- 18.1.2 The TimePrinter class
- 18.1.3 The API routes
- 18.1.4 The HTTP server
- 18.1.5 Let's try it out!
- 18.2 Possible improvements to our solution
- Summary
- Unit 4. Immutable data and structures
- 19 Case classes to structure your data
- 19.1 Case class
- 19.2 Pattern matching and case classes
- 19.3 Case object
- Summary
- Answers to quick checks
- 20 Higher order functions
- 20.1 Functions as parameters
- 20.2 Functions as return values
- Summary
- Answers to quick checks
- 21 What is purity?
- 21.1 A definition of purity
- 21.2 Differentiating between pure and impure functions
- Summary
- Answers to quick checks
- 22 Option
- 22.1 Why Option?
- 22.2 Creating an Option
- 22.3 Pattern matching on Option
- Summary
- Answers to quick checks
- 23 Working with Option: map and flatMap
- 23.1 Transforming an Option
- 23.1.1 The map function
- 23.1.2 The flatten function
- 23.1.3 The flatMap function
- Summary
- Answers to quick checks
- 24 Working with Option: For-comprehension
- 24.1 For-comprehension on Option
- 24.1.1 For-comprehension as syntactic sugar for nested map and flatMap calls
- 24.1.2 Filtering values within for-comprehension
- 24.2 Other operations on Option
- Summary
- Answers to quick checks
- 25 Tuple and unapply
- 25.1 Tuples
- 25.2 Implementing the unapply method
- Summary
- Answers to quick checks
- 26 Rock, Paper, Scissors, Lizard, Spock!
- 26.1 Implementing Rock, Paper, Scissors, Lizard, Spock!
- 26.1.1 sbt project setup and packages
- 26.1.2 Defining a symbol
- 26.1.3 Representing a player
- 26.1.4 Defining a game
- 26.1.5 The API routes
- 26.1.6 The HTTP server
- 26.1.7 Let's try it out!
- 26.2 Possible improvements to our solution
- Summary
- Unit 5. List
- 27 List
- 27.1 Creating a list
- 27.2 Adding elements to a list
- 27.3 Pattern matching on a list
- Summary
- Answers to quick checks
- 28 Working with List: map and flatMap
- 28.1 The map, flatten, and flatMap operations
- 28.1.1 The map function
- 28.1.2 The flatten function
- 28.1.3 The flatMap function
- 28.2 For-comprehension
- Summary
- Answers to quick checks
- 29 Working with List: Properties
- 29.1 Size of a list
- 29.2 Properties of the elements in a list
- Summary
- Answers to quick checks
- 30 Working with List: Element selection
- 30.1 Selecting an element by its position
- 30.2 Finding an element with given features
- 30.3 Picking the minimum or maximum item
- Summary
- Answers to quick checks
- 31 Working with List: Filtering
- 31.1 Dropping and taking elements
- 31.2 Filtering Items of a list
- 31.3 Removing duplicates
- Summary
- Answers to quick checks
- 32 Working with List: Sorting and other operations
- 32.1 Sorting elements
- 32.2 Converting a list to a string
- 32.3 Sum elements of numerical sequences
- 32.4 Grouping elements by feature
- Summary
- Answers to quick checks
- 33 The movies dataset
- 33.1 Download the base project
- 33.2 Parsing a movie entity
- 33.3 Printing query results
- 33.4 Querying the movie data set
- Summary
- Unit 6. Other collections and error handling
- 34 Set
- 34.1 Creating a set
- 34.2 Adding and removing elements
- 34.3 The map, flatten, and flatMap operations
- 34.3.1 The map function
- 34.3.2 The flatten function
- 34.3.3 The flatMap function
- 34.4 For-comprehension
- Summary
- Answers to quick checks
- 35 Working with Set
- 35.1 The Union, Intersection, and Difference operations
- 35.2 Other operations on Set
- Summary
- Answers to quick checks
- 36 Map
- 36.1 Creating Map
- 36.2 Adding and removing elements
- 36.3 Merge and remove multiple entries
- 36.4 The map and flatMap operations
- 36.4.1 The map function
- 36.4.2 The flatMap function
- 36.5 For-comprehension
- Summary
- Answers to quick checks
- 37 Working with Map
- 37.1 Retrieving a value for a given key
- 37.2 Getting all keys and values
- 37.3 Other operations on Map
- Summary
- Answers to quick checks
- 38 Either
- 38.1 Why Either?
- 38.2 Creating an Either
- 38.3 Pattern matching on Either
- 38.4 The map and flatMap operations
- 38.4.1 The map function
- 38.4.2 The flatMap function
- 38.5 For-comprehension
- Summary
- Answers to quick checks
- 39 Working with Either
- 39.1 Retrieving an Either value
- 39.2 Properties of an Either value
- Summary
- Answers to quick checks
- 40 Error handling with Try
- 40.1 Creating a Try
- 40.2 Pattern matching on Try
- 40.3 The map, flatten, and flatMap operations
- 40.3.1 The map function
- 40.3.2 The flatten function
- 40.3.3 The flatMap function
- 40.4 For-comprehension
- 40.5 Other operations on Try
- Summary
- Answers to quick checks
- 41 The library application
- 41.1 Download the base project
- 41.2 Parsing a book entity
- 41.3 The business logic layer
- 41.3.1 Performing a book search
- 41.3.2 Reserving a book
- 41.3.3 Returning a book
- 41.4 Let's give it a try!
- 41.5 Possible improvements to our solution
- Summary
- Unit 7. Concurrency
- 42 Implicit and type classes
- 42.1 Implicit parameters and values
- 42.2 Implicit resolution
- 42.3 Type classes
- Summary
- Answers to quick checks
- 43 Future
- 43.1 Why Future?
- 43.2 Creating an instance of Future
- 43.3 Processing Future on completion
- Summary
- Answers to quick checks
- 44 Working with Future: map and flatMap
- 44.1 The map, flatten, and flatMap operations
- 44.1.1 The map function
- 44.1.2 The flatten function
- 44.1.3 The flatMap function
- Summary
- Answers to quick checks
- 45 Working with Future: For-comprehension and other operations
- 45.1 For-comprehension
- 45.2 Retrieving the first Future to complete
- Summary
- Answers to quick checks
- 46 Database queries with Quill
- 46.1 Project setup
- 46.1.1 Download the base project
- 46.1.2 Starting the PostgreSQL server
- 46.2 Connecting to the PostgreSQL server
- 46.3 Executing queries
- 46.4 Running generated queries
- Summary
- Answers to quick checks
- 47 The quiz application: Part 1
- 47.1 Download the base project
- 47.2 Health check queries
- 47.3 Category queries
- 47.4 Question and answer queries
- 47.5 Let's give it a try!
- Summary
- Unit 8. JSON (de)serialization
- 48 JSON (de)serialization with circe
- 48.1 Project setup
- 48.2 JSON serialization: From instance to JSON
- 48.3 JSON deserialization: From JSON to instance
- Summary
- Answers to quick checks
- 49 Lazy evaluation
- 49.1 By-name parameters
- 49.2 Lazy values
- Summary
- Answers to quick checks
- 50 The IO type
- 50.1 Why IO?
- 50.2 Project setup
- 50.3 Synchronous side effect
- 50.4 Asynchronous side effect
- Summary
- Answers to quick checks
- 51 Working with the IO type
- 51.1 The map and flatMap operations
- 51.1.1 The map function
- 51.1.2 The flatMap function
- 51.2 For-comprehension
- 51.3 Parallel execution
- Summary
- Answers to quick checks
- 52 Testing with ScalaTest
- 52.1 Project setup
- 52.2 Your first test
- 52.3 Asynchronous testing
- Summary
- Answers to quick checks
- 53 The quiz application: Part 2
- 53.1 Download the base project
- 53.2 Generic endpoints
- 53.3 Displaying the available categories
- 53.4 Creating a quiz
- 53.5 Answering a quiz
- 53.6 The HTTP server
- 53.7 Writing tests
- 53.8 Let's give it a try!
- Summary
- Index
- inside back cover
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.