Scala Programming Projects
Mikael Valot Nicolas Jorand更新时间:2021-07-23 16:26:11
最新章节:Leave a review - let other readers know what you think封面
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
Packaging the application
Summary
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
Refactoring monthlyRate
Refactoring simulatePlan
Refactoring SimulatePlanApp
Using ValidatedNel
Adding the cats dependency
Introducing NonEmptyList
Introducing Validated
Refactoring the retirement calculator to use ValidatedNel
Adding unit tests
Implementing parsing functions
Implementing SimulatePlanApp.strSimulatePlan
Refactoring SimulatePlanApp.strMain
Summary
Questions
Further reading
Advanced Features
Project setup
Strictness and laziness
Strict val
lazy val
By-name parameters
Lazy data structures
Covariance and contravariance
InvariantDecoder
CovariantDecoder
Contravariant encoder
Covariance in collections
Currying and partially applied functions
Function value
Currying
Partially applied functions
Implicits
Implicit parameters
Implicit parameter usage
Passing a timeout
Passing an application context
Examples in the SDK
breakOut
executionContext
Implicit conversion
Implicit class
How are implicits resolved?
Summary
Type Classes
Understanding type classes
Type class recipe
Common type classes
scala.math.Ordering
org.scalactic.Equality
cats.Semigroup
Laws
Usage examples
cats.Monoid
Laws
Usage examples
Higher-kinded types
Arity
Higher-order function
Higher-kinded types
cats.Functor
Laws
Usage examples
cats.Apply
Laws
Usage examples
cats.Applicative
Laws
Usage examples
cats.Monad
Laws
Usage examples
Summary
Online Shopping - Persistence
Creating the project
Persistence
Setting up Slick
Setting up the database
Database test
Product test
Cart test
Future
Getting a concrete value
Waiting on a Future
Callback
Composing Futures
Using for-comprehension
Execution context
Rounding up Futures
Database creation
Data Access Object creation
Running the test
Deploying the application
Setting up an account
Deploying your application
Heroku configuration
Summary
Online Shopping - REST API
The REST API
Writing the tests
Defining the routes
Running the test
Checking the API
Implementing the API with persistence
Completing the product tests
Implementing the product API
Product list
Encoding JSON with Circe
Action definition
Adding a product
Completing the cart test
Logging in
Unit test
Implementation
Passing the cookie
Listing products in cart
Swagger
Installing Swagger
Declaring endpoints
Running the application
Login
List of products
Cart endpoints
Deploying on Heroku
Summary
Online Shopping - User Interface
Learning objectives
Setting up
Defining the layout
Creating the layout
Building the page
Main layout
Product list panel
Cart panel
Introducing the UI manager
Adding jQuery to our project
Calling our API
Setting the main method
Initializing the user interface
Implementing UI actions
Adding a product to the cart
Removing a product from the cart
Updating the quantity
Deploying the user interface
Debugging the interface
Summary
Interactive Browser
Actors
Setting up
Implementing the server side
Creating the web socket route
Implementing BrowserManager
Handling WebSocket
A diagram of Actors
Implementing the client side
Adding the web socket
Notifying the user
Extending jQuery
Summary
Fetching and Persisting Bitcoin Market Data
Setting up the project
Understanding Apache Spark
RDD DataFrame and Dataset
Spark SQL
Dataframe
Dataset
Exploring the Spark API with the Scala console
Transforming rows using map
Transforming rows using select
Execution model
Implementing the transaction batch producer
Calling the Bitstamp REST API
Parsing the JSON response
Unit testing jsonToHttpTransaction
Implementing jsonToHttpTransaction
Unit testing httpToDomainTransactions
Implementing httpToDomainTransactions
Saving transactions
Introducing the Parquet format
Writing transactions in Parquet
Using the IO Monad
Putting it all together
Testing processOneBatch
Implementing processOneBatch
Implementing processRepeatedly
Implementing BatchProducerApp
Running the application with spark-submit
Installing Apache Spark
Packaging the assembly JAR
Running spark-submit
Summary
Batch and Streaming Analytics
Introduction to Zeppelin
Installing Zeppelin
Starting Zeppelin
Testing Zeppelin
Structure of a notebook
Writing a paragraph
Drawing charts
Analyzing transactions with Zeppelin
Drawing our first chart
Drawing more charts
Introducing Apache Kafka
Topics partitions and offsets
Producing data into Kafka
Consuming data from Kafka
Consumer group
Offset management
Connecting to Kafka
Streaming transactions to Kafka
Subscribing with Pusher
Deserializing live transactions
Converting to transaction and serializing
Putting it all together
Running StreamingProducerApp
Introducing Spark Streaming
Analyzing streaming transactions with Zeppelin
Reading transactions from Kafka
Writing to an in-memory sink
Drawing a scatter chart
Aggregating streaming transactions
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
更新时间:2021-07-23 16:26:11