更新时间:2021-07-23 16:26:11
封面
Title Page
Copyright and Credits
Scala Programming Projects
Packt Upsell
Why subscribe?
Packt.com
Contributors
About the authors
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Writing Your First Program
Setting up your environment
Installing the Java SDK
Installing IntelliJ IDEA
Using the basic features
SBT synchronization
Build
Running the Scala Console
Using the Scala Console and Worksheet
Using the Scala Console
Declaring variables
Types
Declaring and calling functions
Side effects
If...else expression
Class
Using the worksheet
Class inheritance
Subclass assignment
Overriding methods
Abstract class
Trait
Scala class hierarchy
Case class
Companion object
Creating my first project
Creating the project
Creating the Main object
Writing the first unit test
Implementing another feature
Implementing the Main method
Summary
Developing a Retirement Calculator
Project overview
Calculating the future capital
Writing a unit test for the accumulation phase
Implementing futureCapital
Refactoring the production code
Writing a test for the decumulation phase
Simulating a retirement plan
Writing a failing unit test
Working with tuples
Implementing simulatePlan
Calculating when you can retire
Writing a failing test for nbOfMonthsSaving
Writing the function body
Understanding tail-recursion
Ensuring termination
Using market rates
Defining an algebraic data type
Filtering returns for a specific period
Pattern matching
Refactoring simulatePlan
Loading market data
Writing the unit test using the column selection mode
Loading the file with Source
Loading inflation data
Computing real returns
Packaging the application
Creating the App object
Handling Errors
Setup
Using exceptions
Throwing exceptions
Catching exceptions
Using the finally block
Ensuring referential transparency
Defining pure functions
Best practices
Showing how exceptions break referential transparency
Using Option
Manipulating instances of Option
Composing transformations with for... yield
Refactoring the retirement calculator to use Option
Using Either
Manipulating Either
Refactoring the retirement calculator to use Either
Refactoring nbOfMonthsSavings