Practical FP in Scala: A hands-on approach
Practical FP in Scala: A hands-on approach
$14.99
Minimum price
$19.99
Suggested price
Practical FP in Scala: A hands-on approach

This book is 65% complete

Last updated on 2019-11-18

About the Book

Practical FP in Scala: A hands-on approach, is a book for intermediate to advanced Scala developers. Aimed at those who understand functional effects, referential transparency and the benefits of functional programming to some extent but who are missing some pieces to put all these concepts together to build a large application in a time-constrained manner.

Throughout the chapters we will design, architect and develop a complete stateful application serving an API via HTTP, accessing a database and dealing with cached data, using the best practices and best functional libraries available in the Cats ecosystem.

You will also learn about common design patterns such as managing state, error handling and anti-patterns, all accompanied by clear examples. Furthermore, at the end of the book, we will dive into some advanced concepts such as MTL, Classy Optics and Typeclass derivation.

Got some feedback? Please email the author here: pfpscala@gmail.com.

About the Author

Gabriel Volpe
Gabriel Volpe

Gabriel Volpe is a Software Engineer, specialized in functional programming, from Buenos Aires, Argentina. He has been writing code since 2005, using Scala professionally since 2014 and Haskell since 2017. He is also the author of some open-source Scala libraries such as Fs2 Rabbit and Redis4Cats. You can find him giving talks at functional programming conferences and meetups all over the world as well as helping people out on Gitter.

Table of Contents

  • Preface
  • Acknowledgments
  • Dependency version
  • Prerequisites
  • Conventions used in this book
  • 1. Chapter 1: Shopping Cart project
    • 1.1 Business requirements
      • 1.1.1 Third-party Payments API
      • 1.1.2 Identifying the domain
      • 1.1.3 Identifying Http endpoints
    • 1.2 Architecture
    • 1.3 Technical stack
      • 1.3.1 A note on Cats Effect
  • 2. Chapter 2: Design patterns
    • 2.1 Strongly-typed functions
      • 2.1.1 Value classes
      • 2.1.2 Newtypes
      • 2.1.3 Refinement types
    • 2.2 Encapsulating state
      • 2.2.1 In-memory counter
    • 2.3 Sequential vs concurrent state
      • 2.3.1 State Monad
      • 2.3.2 Atomic Ref
    • 2.4 Shared state
      • 2.4.1 Regions of sharing
      • 2.4.2 Leaky state
    • 2.5 Anti-patterns
      • 2.5.1 Seq: a base trait for sequences
      • 2.5.2 About Monad Transformers
    • 2.6 Error handling
      • 2.6.1 MonadError and ApplicativeError
      • 2.6.2 Either Monad
      • 2.6.3 Classy prisms
  • 3. Chapter 3: Tagless final encoding
    • 3.1 Algebras
      • 3.1.1 Naming conventions
    • 3.2 Interpreters
      • 3.2.1 Building interpreters
    • 3.3 Programs
    • 3.4 Implicit vs explicit parameters
      • 3.4.1 Achieving modularity
      • 3.4.2 Implicit convenience
  • 4. Chapter 4: Business logic
    • 4.1 Identifying algebras
    • 4.2 Data access and storage
    • 4.3 Defining programs
      • 4.3.1 Checkout
      • 4.3.2 Retrying effects
  • 5. Chapter 5: HTTP layer
    • 5.1 A server is a function
    • 5.2 HTTP Routes #1
    • 5.3 Authentication
      • 5.3.1 JWT Auth
    • 5.4 HTTP Routes #2
    • 5.5 Composing routes
    • 5.6 Middlewares
      • 5.6.1 Compositionality
    • 5.7 Running server
    • 5.8 Entity codecs
      • 5.8.1 JSON codecs
      • 5.8.2 Validation
    • 5.9 HTTP Client
      • 5.9.1 Payment client
      • 5.9.2 Creating a client
  • 6. Chapter 6: Persistent layer
    • 6.1 Skunk & Doobie
      • 6.1.1 Session Pool
      • 6.1.2 Queries
      • 6.1.3 Commands
      • 6.1.4 Interpreters
      • 6.1.5 Streaming & Pagination
    • 6.2 Redis for Cats
      • 6.2.1 Connection
      • 6.2.2 Interpreters
    • 6.3 Blocking operations
    • 6.4 Health check
  • 7. Chapter 7: Testing
    • 7.1 Functional test suite
    • 7.2 Generators
    • 7.3 Business logic
      • 7.3.1 Happy path
      • 7.3.2 Empty cart
      • 7.3.3 Unreachable payment client
      • 7.3.4 Recovering payment client
      • 7.3.5 Failing orders
      • 7.3.6 Failing cart deletion
    • 7.4 Http routes
    • 7.5 Integration tests
      • 7.5.1 Postgres
      • 7.5.2 Redis
  • 8. Chapter 8: Assembly
    • 8.1 Logging
    • 8.2 Configuration
    • 8.3 Modules
  • 9. Chapter 9: Deploying
    • 9.1 Docker containers
    • 9.2 CI build and Heroku
  • 10. Chapter 10: Advanced techniques
    • 10.1 MTL (Monad Transformers Library)
    • 10.2 Classy optics
    • 10.3 Typeclass derivation

Authors have earned$8,182,613writing, publishing and selling on Leanpub,
earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.

Learn more about writing on Leanpub

The Leanpub 45-day 100% Happiness Guarantee

Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms

Free Updates. Free App. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets), MOBI (for Kindle) and in the free Leanpub App (for Mac, Windows, iOS and Android). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses! Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks. Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. It really is that easy.

Learn more about writing on Leanpub