Learn Scala Programming

Book description

"

A step-by-step guide in building high-performance scalable applications with the latest features of Scala.

Key Features

  • Develop a strong foundation in functional programming and Scala's Standard Library (STL)
  • Get a detailed coverage of Lightbend Lagom—the latest microservices framework from Lightbend
  • Understand the Akka framework and learn event-based Programming with Scala

Book Description

The second version of Scala has undergone multiple changes to support features and library implementations. Scala 2.13, with its main focus on modularizing the standard library and simplifying collections, brings with it a host of updates.

Learn Scala Programming addresses both technical and architectural changes to the redesigned standard library and collections, along with covering in-depth type systems and first-level support for functions. You will discover how to leverage implicits as a primary mechanism for building type classes and look at different ways to test Scala code. You will also learn about abstract building blocks used in functional programming, giving you sufficient understanding to pick and use any existing functional programming library out there. In the concluding chapters, you will explore reactive programming by covering the Akka framework and reactive streams.

By the end of this book, you will have built microservices and learned to implement them with the Scala and Lagom framework.

What you will learn

  • Acquaint yourself with the new standard library of Scala 2.13
  • Get to grips with the Grok functional paradigms
  • Get familiar with type system to express domain constraints
  • Understand the actor model and different Akka libraries
  • Grasp the concept of building microservices using Lagom framework
  • Deep dive into property-based testing and its practical applications

Who this book is for

This book is for beginner to intermediate level Scala developers who would like to advance and gain knowledge of the intricacies of the Scala language, expand their functional programming tools, and explore actor-based concurrency models.

"

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Learn Scala Programming
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. Packt.com
  5. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. An Introduction to Scala 2.13
    1. Technical requirements
    2. Introduction to Scala 2.13
    3. New features of Scala 2.13
      1. Optional parsing for string literals
      2. Products can report the names of their element
      3. Added methods for chaining operations
      4. Automatic Resource Management
    4. The Scala 2.13 Collection Library
      1. IterableOnceOps
      2. IterableOps
        1. WithFilter
        2. IterableFactory
        3. View
      3. Set
      4. Map
        1. SortedMap
        2. HashMap
        3. MultiMap
        4. SeqMap
      5. Seq
        1. IndexedSeq
        2. LinearSeq
        3. Buffers
      6. Scala Collection Contrib library
    5. Summary
    6. Questions
    7. Further reading
  8. Understanding Types in Scala
    1. Technical requirements
    2. Understanding types
      1. Ways to create a type
      2. Literal types
      3. Compound (intersection) types
      4. Type constraints
      5. Scala's types hierarchy and special types
      6. Type inference
      7. Path-dependent types
    3. Types – all the way down
      1. Type parameters
      2. Type members
      3. Generalized type constraints
      4. Infix types
      5. Variance
      6. Existential types
      7. Higher kinded types
      8. Type lambdas
    4. Using types to define domain constraints
      1. Phantom types
      2. Self-recursive types
    5. Summary
    6. Questions
    7. Further reading
  9. Deep Dive into Functions
    1. Technical requirements
    2. Ways to define a function
      1. Function as a method
      2. Local functions
      3. Closures
      4. Partial application and functions
      5. Function literals 
      6. Currying
    3. Polymorphism and higher order functions
      1. Polymorphic functions
      2. Higher-order functions
    4. Recursion and trampolining
      1. Recursion
      2. Tail recursion
      3. Trampolining
    5. Object-oriented aspects of functions
      1. Functions are traits
      2. Partial functions
      3. Function object
      4. Extending functions
    6. Summary
    7. Questions
    8. Further reading
  10. Getting to Know Implicits and Type Classes
    1. Technical requirements
    2. Types of implicits
      1. Implicit conversions
      2. Implicit parameters
      3. Implicit classes
    3. View and context bounds
      1. View bounds
      2. Context bounds
    4. Type classes
      1. Type classes
      2. Type class recursive resolution
      3. Type class variance
    5. Implicit scope resolution
      1. Lexical scope
      2. Implicit scope
      3. Static overloading rules
    6. Summary
    7. Questions
    8. Further reading
  11. Property-Based Testing in Scala
    1. Technical requirements
    2. Introduction to property-based testing
      1. From unit tests to properties
      2. ScalaCheck
    3. Properties
      1. Types of properties
        1. Commutativity
        2. Associativity
        3. Identity
        4. Invariants
        5. Idempotence
        6. Induction 
        7. Symmetry
        8. Test Oracle
      2. Defining a property
        1. Checking property
        2. Combining properties
    4. Generators
      1. Existing generators
      2. Combining generators
      3. Shrinkers
    5. Summary
    6. Questions
  12. Exploring Built-In Effects
    1. Technical requirements
    2. Introduction to effects
    3. Option
      1. Creating an Option
      2. Reading from an Option
      3. Option as an effect
    4. Either
      1. Creating Either
      2. Reading values from Either
      3. Either as an Effect
    5. Try
      1. Creating a Try
      2. Reading values from Try
      3. Try as an effect
    6. Future
      1. Creating a Future
      2. Reading values from a Future
      3. Future as an effect
    7. Summary
    8. Questions
  13. Understanding Algebraic Structures
    1. Technical requirements
    2. Introduction to abstract algebraic structures
    3. Semigroup
    4. Monoid
    5. Foldable
    6. Group
    7. Summary
    8. Questions
    9. Further reading
  14. Dealing with Effects
    1. Technical requirements
    2. Functor
    3. Applicative
    4. Traversable
    5. Summary
    6. Questions
    7. Further reading
  15. Familiarizing Yourself with Basic Monads
    1. Technical requirements
    2. Introduction to monads
    3. Id Monad
    4. State monad
    5. Reader monad
    6. Writer monad
    7. Summary
    8. Questions
    9. Further reading
  16. A Look at Monad Transformers and Free Monad
    1. Technical requirements
    2. Combining monads
    3. Monad transformers
    4. Monad transformers stacks
    5. Free monads
    6. Summary
    7. Questions
    8. Further reading
  17. An Introduction to the Akka and Actor Models
    1. Technical requirements
    2. Introduction to the actor model
    3. Akka basics
      1. Defining actors
      2. The life cycle of an actor
      3. Dispatchers
      4. Terminating actors
      5. The ask pattern
      6. Changing an actor's behavior using context
    4. Advanced topics
      1. Akka FSM
      2. Akka remoting
      3. The actor path
      4. Actor supervision
    5. Testing actors
    6. Running the application
    7. Summary
    8. Questions
    9. Further reading
  18. Building Reactive Applications with Akka Typed
    1. Technical requirements
    2. Introduction
      1. The typed approach and the differences between Akka untyped
      2. Example actor system
      3. First example
    3. Akka Typed basics
      1. Creating an actor
      2. Stopping an actor
      3. Discovering an actor
    4. Akka Typed – beyond the basics
      1. Life cycle of an actor
      2. Supervision
      3. Watching an actor
      4. Timers
      5. Stashing
      6. Combining behaviors
      7. Cluster
    5. Testing
      1. Dependencies and setup
      2. Synchronous testing
      3. Asynchronous testing
    6. Running the application
    7. Summary
  19. Basics of Akka Streams
    1. Technical requirements
    2. Introduction to Akka Streams
      1. Reactive Streams and backpressure
      2. Akka Streams
      3. Setup and dependency
      4. Essential concepts
      5. Structure of the example
    3. Basics of Akka Streams
      1. Sources and sinks
      2. Flows 
      3. Graphs
      4. Logging
      5. Materialization
      6. Handling failure
    4. Testing
      1. Akka TestKit
      2. Streams TestKit
    5. Running the application
    6. Summary
    7. Questions
    8. Further reading
  20. Project 1 - Building Microservices with Scala
    1. Technical requirements
    2. Essentials of microservices
    3. Building a microservice with http4s and doobie
      1. Project structure
      2. FS2 – functional streams
      3. Database migrations
      4. Configuration with PureConfig
      5. Doobie – functional database access
      6. http4s – streaming HTTP
      7. Bringing it all together
      8. Testing
      9. Running the application
    4. Building microservices with Akka-HTTP and Akka Persistence
      1. Project structure
      2. Event-Sourcing and CQRS
      3. Configuring Akka Persistence
      4. Domain models
      5. The persistent actor
      6. Akka-HTTP
      7. Bringing it all together
      8. Testing
      9. Running the application
    5. Summary
    6. Questions
    7. Further reading
  21. Project 2 - Building Microservices with Lagom
    1. Technical requirements
    2. Why Lagom?
    3. Project overview and setup
      1. The bakery project
      2. Project setup
    4. Lagom's APIs
      1. Service API
      2. Persistence API
      3. Message Broker API
      4. Service API from the client side
    5. Running the application
    6. Testing
    7. Summary
    8. Questions
    9. Further reading
  22. Preparing the Environment and Running Code Samples
    1. Installing software
      1. Installing Java Virtual Machine (JVM)
      2. Installing SBT
    2. Working with the code
      1. Getting the code
      2. Working with the source code
      3. Using the SBT console
      4. Using REPL
  23. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
    14. Chapter 14
    15. Chapter 15
  24. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Learn Scala Programming
  • Author(s): Slava Schmidt
  • Release date: October 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788836302