Book Image

Professional Scala

By : Mads Hartmann, Ruslan Shevchenko
Book Image

Professional Scala

By: Mads Hartmann, Ruslan Shevchenko

Overview of this book

This book teaches you how to build and contribute to Scala programs, recognizing common patterns and techniques used with the language. You’ll learn how to write concise, functional code with Scala. After an introduction to core concepts, syntax, and writing example applications with scalac, you’ll learn about the Scala Collections API and how the language handles type safety via static types out-of-the-box. You’ll then learn about advanced functional programming patterns, and how you can write your own Domain Specific Languages (DSLs). By the end of the book, you’ll be equipped with the skills you need to successfully build smart, efficient applications in Scala that can be compiled to the JVM.
Table of Contents (12 chapters)

Index

A

  • abstract type members
    • about / Abstract Type Members
  • Actors
    • URL / Akka
  • advanced types
    • about / Advanced Types
    • abstract type members / Abstract Type Members
    • structural types / Structural Types
  • Akka
    • about / Akka
    • URL / Akka
  • AnyRef
    • about / A Unified Type System
  • Any type
    • about / A Unified Type System
    • AnyVal / A Unified Type System
    • AnyRef / A Unified Type System
  • AnyVal
    • about / A Unified Type System
  • Apache Spark
    • about / Apache Spark
    • URL / Apache Spark

B

  • base syntax, Scala
    • about / Base Syntax
    • for definitions / Base Syntax for Definitions
    • for expressions / Base Syntax for Expressions
  • basic sbt commands
    • sbt compile / Basic sbt Commands
    • sbt run / Basic sbt Commands
  • binary search tree
    • implementation, generalizing / Activity: Generalizing the Implementation of the Binary Tree
  • binary search tree implementation
    • generalizing / Activity: Generalizing the Implementation of the Binary Tree
  • bottom type
    • about / A Unified Type System
  • bounds
    • about / Bounds
  • by-name parameters
    • about / By-Name Parameters
  • by name parameter passing mode
    • about / By Name
  • by need parameter passing mode
    • about / By Need
  • by value parameter passing mode
    • about / By Value

C

  • category theory
    • about / Functional Design Patterns
  • Cats library
    • about / Validating Data Using Cats, Introduction to Cats
    • reference link / Validating Data Using Cats
    • used, for data validation / Validating Data Using Cats, Validating Data
    • prerequisites / Prerequisites for Using Cats
    • data validation, with Validated data type / Validating Using Validated
  • chatbot
    • OO, implementing in / OO in Our Chatbot
    • environment and logic, decoupling / Decoupling Logic and Environment
    • ConsoleOutput, implementing / Decoupling Logic and Environment
    • DefaultTimeProvider, implementing / Decoupling Logic and Environment
    • simple TODO-list, adding / Using Lifting for Conversations between Total and Partial Functions
  • ChatbotMode
    • representing, as partial function / Representing ChatbotMode as a Partial Function
  • chatbot modes
    • logic, encapsulating, in sealed traits / Sealed Traits and Algebraic Datatypes
    • logic, encapsulating in algebraic datatypes / Sealed Traits and Algebraic Datatypes
  • classes
    • about / Objects, Classes, and Traits, Classes
    • CartesianPoint case class, defining / Classes
    • equality class / Equality and Case Classes
    • case class / Equality and Case Classes
    • pattern matching / Pattern Matching
  • collection
    • lists / Working with Lists
    • abstracting on sequences / Abstracting on Sequences
    • sets / Sets
    • tuples / Tuples
    • map / Maps
    • immutable collection / Mutable and Immutable Collections
    • mutable collection / Mutable and Immutable Collections
  • ConnectionIO
    • about / ConnectionIO
  • ConsoleOutput
    • implementing / Decoupling Logic and Environment
  • context bounds
    • about / Context Bounds and Implicitly
  • contravariance
    • about / Contravariance
  • covariance
    • about / Covariance
    • implementing, for tools / Activity: Implementing Covariance and the Database for Tools
  • CurrentTime query
    • modes, creating / Sealed Traits and Algebraic Datatypes
  • currying
    • about / Currying Forms (Multiple Argument Lists)

D

  • data validation
    • performing ,Cats library used / Validating Data Using Cats, Validating Data
  • default parameters
    • about / Default Parameters
  • DefaultTimeProvider
    • implementing / Decoupling Logic and Environment
  • def macros
    • about / Def Macros
  • Domain Specific Languages (DSLs)
    • about / DSLs and Types of DSLs
    • types / DSLs and Types of DSLs
    • external DSLs / External DSLs
    • internal DSLs / Internal DSLs
    • language features, for writing / Language Features for Writing DSLs
    • implementing / Writing a Small DSL
    • creating, for test cases / DSL for TestCase
    • creating, for specifying assertions / Activity: Creating a DSL to Specify Assertions
  • Doobie library
    • about / Communicating with Databases Using Doobie, Doobie
    • used, for database communication / Communicating with Databases Using Doobie
    • prerequisites / Prerequisites for Doobie
    • using / Prerequisites for Doobie
    • ConnectionIO / ConnectionIO
    • Transactor / Transactor
    • rows, selecting / Selecting Rows
    • querying with parameters / Querying Using Parameters
    • rows, deleting / Deleting, Inserting, and Updating Rows
    • rows, inserting / Deleting, Inserting, and Updating Rows
    • rows, updating / Deleting, Inserting, and Updating Rows
    • example / A Complete Example

E

  • element
    • searching, based on given predicate / Activity: Finding an Element Based on a Given Predicate, Summary
  • evenInts method
    • implementing / Pattern Matching on Lists
  • existential type
    • about / Existential Types
    • using / Existential Types
  • extension methods
    • creating / Activity: Creation of Extension Methods
    • about / Extension Methods and Value Classes
  • external DSLs
    • about / External DSLs

F

  • FeatureSpec
    • about / Overview of ScalaTest Styles
  • Fibonacci Series
    • implementing, with streams and iterators / Activity: Implementing Fibonacci Series Using Streams and Iterators
  • first-order methods
    • about / First-Order Methods on List
  • FlatSpec
    • about / Overview of ScalaTest Styles
  • flexible syntax, for method invocations
    • about / Flexible Syntax for Method Invocation
    • rules / Flexible Syntax for Method Invocation
  • forms
    • currying / Currying Forms (Multiple Argument Lists)
  • FreeSpec
    • about / Overview of ScalaTest Styles
  • functional design patterns
    • about / Functional Design Patterns
    • Monoids / Functional Design Patterns, Monoids
    • Functors / Functional Design Patterns, Functor
    • Monads / Monads
  • functional programming
    • core concepts / Introduction to Functional Programming Concepts
  • function calls
    • about / Syntax Goodies
    • named parameters / Named Parameters
    • default parameters / Default Parameters
    • multiple argument lists / Currying Forms (Multiple Argument Lists)
    • special magic methods / Special Magic Methods
  • function definition
    • syntax sugar / Syntax Sugar in a Function Definition
  • functions
    • about / Functions
    • function values / Function Values
    • defining, from OO point of view / Function from an OO Point of View
    • creating / Function from an OO Point of View
    • conversions / Conversions, Defining and Measuring the Time of a Unit Function
    • partial functions / Partial Functions
  • function variable
    • defining / Function Values
  • Functor
    • about / Functor
    • examples / Functor
    • defining, for option / Functor
  • FunSpec
    • about / Overview of ScalaTest Styles
  • FunSuite
    • about / Overview of ScalaTest Styles
    • example / Overview of ScalaTest Styles

H

  • higher-order function
    • example / Higher-Order Functions
    • implementing / Higher-Order Functions
  • higher kind types
    • about / Higher Kind Types

I

  • IDE
    • about / IDE
    • sample project, loading in / Activity: Loading and Running a Sample Project in the IDE
    • sample project, running in / Activity: Loading and Running a Sample Project in the IDE
  • immutability
    • about / Pure Functions, Immutability
    • examples / Immutability
  • immutable collection
    • about / Mutable and Immutable Collections
  • implicit conversions
    • about / Implicit Conversions
  • implicitly
    • about / Context Bounds and Implicitly
  • implicit macros
    • about / Implicit Macros
  • implicit parameters
    • about / Implicit Parameters
  • implicit resolution
    • about / Implicit Resolution
  • internal DSLs
    • about / Internal DSLs
    • shallow / Internal DSLs
    • deep / Internal DSLs
  • invariance
    • about / Invariance
  • isEmpty method / Operations on Lists
  • isSuitable function
    • about / Covariance
  • Iterable trait
    • about / Iterators
  • iterators
    • about / Iterators

L

  • language features
    • about / Uncovered Language Features
    • macros / Macros
    • reflection / Reflection
  • language features, for writing DSLs
    • about / Language Features for Writing DSLs
    • flexible syntax, for method invocation / Flexible Syntax for Method Invocation
    • by-name parameters / By-Name Parameters
    • extension methods / Extension Methods and Value Classes
    • value classes / Extension Methods and Value Classes
  • lists
    • working with / Working with Lists
    • constructing / Constructing Lists
    • operations / Operations on Lists
    • pattern matching / Pattern Matching on Lists
    • first-order methods / First-Order Methods on List
    • appending / Appending and Concatenation
    • concatenation / Appending and Concatenation
    • length, taking / Taking the Length of a List
    • reversing / Reversing a List
    • prefixes / Prefixes and Suffixes
    • suffixes / Prefixes and Suffixes
    • element selection / Element Selection
    • display / Display
    • used, for creating new mode in chatbot / Activity: Creating a New Mode for Chatbot Using Lists
  • log statement
    • creating / Printing the log Argument to the Console and File

M

  • macros
    • about / Macros
    • URL, for official documentation / Macros
    • def macros / Def Macros
    • implicit macros / Implicit Macros
  • magic methods
    • about / Special Magic Methods
  • maps
    • about / Maps
  • memory leak
    • about / Implementing RemindStore as a Set of Partial Functions
    • identifying, in StoreRemindCommand / Implementing RemindStore as a Set of Partial Functions
    • fixing, in StoreRemindCommand / Implementing RemindStore as a Set of Partial Functions
  • mkString method
    • about / Display
  • mode command
    • creating / Printing the log Argument to the Console and File
  • monad
    • about / The Traversable Trait
  • Monad
    • about / Monads
    • pure operation / Monads
    • flatMap operation / Monads
    • example / Monads
    • defining, for Option / Monads
  • monadic mechanism
    • about / The Traversable Trait
  • Monoid
    • about / Monoids
    • combine operation / Monoids
    • empty operation / Monoids
    • instance, defining for String / Monoids
    • used, for writing polymorphic functions / Using Monoids to Write Polymorphic Functions
  • multiple argument lists
    • using / Currying Forms (Multiple Argument Lists)
  • mutable collection
    • about / Mutable and Immutable Collections

N

  • named parameters
    • about / Named Parameters
  • nextHanoi function
    • implementing / Activity: Implementing the Tower of Hanoi Problem
  • Nothing type
    • about / A Unified Type System
  • Null type
    • about / A Unified Type System

O

  • objects
    • about / Objects, Classes, and Traits, Object
    • defining / Object
  • OrMode
    • implementing / Using Lifting for Conversations between Total and Partial Functions

P

  • parameterized types
    • about / Parameterized Types
  • parameter passing mode
    • about / Parameter-Passing Mode
    • by value / By Value
    • by name / By Name
    • by need / By Need
  • parametric polymorphism
    • about / Parametric Polymorphism
  • partial functions
    • about / Partial Functions
    • defining / Partial Functions
    • implementing / Partial Functions in Practice
    • ChatbotMode, representing as / Representing ChatbotMode as a Partial Function
    • RemindStore, implementing as set of partial functions / Implementing RemindStore as a Set of Partial Functions
    • drawbacks / Using Lifting for Conversations between Total and Partial Functions
    • total functions, representing as / Using Lifting for Conversations between Total and Partial Functions
    • lift method / Using Lifting for Conversations between Total and Partial Functions
    • unlift method / Using Lifting for Conversations between Total and Partial Functions
  • paths inner function
    • implementing / Activity: Implementing the Tower of Hanoi Problem
  • pattern matching
    • about / Pattern Matching
    • using / Pattern Matching
    • exploring / Exploring Pattern Matching
    • minimal example / Exploring Pattern Matching
    • variables, binding in pattern matcher / Binding a Sequence of Variables in the Pattern Matcher
    • custom unapplySeq mehod, implementing / Binding a Sequence of Variables in the Pattern Matcher
  • polymorphism
    • about / Types of Polymorphism
    • types / Types of Polymorphism
    • ad hoc polymorphism / Types of Polymorphism
  • popular libraries
    • about / Popular Libraries
    • Cats library / Validating Data Using Cats
    • Doobie library / Communicating with Databases Using Doobie
  • priority
    • designing, for application / Activity: Adding Priority to the Todo List
  • project structure, Scala
    • about /
    • basic sbt commands / Basic sbt Commands
  • PropSpec
    • about / Overview of ScalaTest Styles
  • pure functions
    • examples / Pure Functions

Q

  • Quasiquotes
    • about / Quasiquotes

R

  • reflection
    • using / Reflection
  • RemindStore
    • implementing, as set of partial function / Implementing RemindStore as a Set of Partial Functions
  • REPL
    • about / REPL
    • expressions, evaluating / REPL, Obtaining the Time Request from Our Chatbot Program
  • runnable construction
    • creating / Creating a Runnable Construction

S

  • sbt package
    • about / Basic sbt Commands
  • SBT project
    • testing / Adding ScalaTest to Your Project
  • sbt publish
    • about / Basic sbt Commands
  • sbt tests
    • running, from command line / Adding a Test to Our Project
    • running, from IDEA IDE / Adding a Test to Our Project
  • Scala
    • base syntax / Base Syntax
    • unit testing / Unit Testing
    • objects / Objects, Classes, and Traits, Object
    • classes / Objects, Classes, and Traits, Classes
    • traits / Objects, Classes, and Traits, Traits
    • special classes / Special Classes
  • Scala Improvement Process (SIP)
    • about / Scala Improvement Process
    • URL / Scala Improvement Process
  • Scala libraries
    • Akka / Akka
    • Apache Spark / Apache Spark
    • Shapeless / Shapeless
  • Scala Newsletters / Scala Times
  • Scala Platform Process (SPP)
    • about / Scala Improvement Process
  • Scala project
    • structure /
    • binary compatibility / Basic sbt Commands
    • basic operations, performing with sbt / Basic sbt Commands, Activity: Performing Basic Operations with sbt: Build, Run, Package
    • loading, in IDE / Activity: Loading and Running a Sample Project in the IDE
    • running, in IDE / Activity: Loading and Running a Sample Project in the IDE
  • ScalaTest
    • about / Internal DSLs, ScalaTest – A Popular DSL
    • adding, to project / Adding ScalaTest to Your Project
    • styles / Adding ScalaTest to Your Project, Overview of ScalaTest Styles
  • Scala Times
    • about / Scala Times
    • URL / Scala Times
  • self-types annotation
    • about / Self-Types
    • exploring / Self-Types
  • sets
    • about / Sets
  • Shapeless
    • about / Shapeless
    • using / Shapeless
  • special classes
    • functions / Special Classes
    • tuples / Special Classes
  • standard library
    • implementing / Implementing the standard library
  • streams
    • about / Streams
  • Streams
    • URL / Akka
  • structural types
    • about / Structural Types
    • option / Option
    • higher kind types / Higher Kind Types
    • type erasure / Type Erasure
  • styles, ScalaTest
    • about / Overview of ScalaTest Styles
    • FunSuite / Overview of ScalaTest Styles
    • FlatSpec / Overview of ScalaTest Styles
    • FunSpec / Overview of ScalaTest Styles
    • FreeSpec / Overview of ScalaTest Styles
    • PropSpec / Overview of ScalaTest Styles
    • FeatureSpec / Overview of ScalaTest Styles
    • implementing / Activity: Implementing ScalaTest Styles
  • syntax sugar, in function definition
    • about / Syntax Sugar in a Function Definition

T

  • test cases
    • modeling / Modeling Test Cases
    • DSLs, creating for / DSL for TestCase
  • tests
    • adding, to Scala project / Adding a Test to Our Project
    • about / Inside Tests
    • another test, adding / Inside Tests
    • running, for chatbot / Running Tests for Chatbot
  • Todo lists
    • priority, adding / Activity: Adding Priority to the Todo List
  • top type / A Unified Type System
  • Tower of Hanoi problem
    • about / Activity: Implementing the Tower of Hanoi Problem
    • reference link / Activity: Implementing the Tower of Hanoi Problem
    • implementing / Activity: Implementing the Tower of Hanoi Problem
  • traits
    • about / Objects, Classes, and Traits, Traits
    • example / Traits
    • self-types annotation / Self-Types
  • Transactor
    • about / Transactor
  • Traversable
    • about / Abstracting on Sequences
  • Traversable trait
    • about / The Traversable Trait
  • tuples
    • about / Tuples
    • creating / Tuples
  • type classes
    • about / Type Classes
    • in standard library / Type Classes in the Standard Library
    • implementing, for supporting conversion / Activity: Implementing Type Classes to Support Conversion
  • type erasure
    • about / Type Erasure
  • type inference
    • about / Type Inference
  • type system
    • unified type system / A Unified Type System
    • Any / A Unified Type System
    • parametric polymorphism / Parametric Polymorphism
    • type inference / Type Inference
    • parameterized types / Parameterized Types
    • bounds / Bounds
    • existential type / Existential Types

U

  • unified type system
    • about / A Unified Type System
  • unit testing
    • about / Unit Testing
    • tests, adding to program / Adding a Test to Our Project
    • sbt tests, running from command line / Adding a Test to Our Project
    • sbt tests, running from IDEA IDE / Adding a Test to Our Project
    • simple test / Inside Tests

V

  • Validated data type
    • about / Validating Using Validated
    • used, for data validation / Validating Using Validated
  • value classes
    • about / Extension Methods and Value Classes
  • variance
    • about / Variance
    • covariance / Covariance
    • contravariance / Contravariance
    • invariance / Invariance