We may earn an affiliate commission when you visit our partners.
Leandro Galvan

When you first hear about functional programming you might get the impression that it can only be used in toy examples or for very academic purposes. After all, FP is all about purity and almost every useful thing you can do in a program is impure: http calls, file IO, and so on.

In this course I'm going to show you that FP is actually amazing for dealing with effects. By separating program description from execution you will be able to build computations that are easy to compose and reason about, while at the same time keeping all the usefulness of side-effects.

Read more

When you first hear about functional programming you might get the impression that it can only be used in toy examples or for very academic purposes. After all, FP is all about purity and almost every useful thing you can do in a program is impure: http calls, file IO, and so on.

In this course I'm going to show you that FP is actually amazing for dealing with effects. By separating program description from execution you will be able to build computations that are easy to compose and reason about, while at the same time keeping all the usefulness of side-effects.

In order to do so, we are going to use the amazing Cats Effect library, which provides an IO monad to model our effects, a very rich API to compose them, and a highly-performant runtime to execute them.

The course is structured in many small/medium sized sections that focus on one specific topic. At the end of each section there is a final exercise to practice what you learned, and a quiz to help check your recall and understanding of the section.

By the end of the course, you will be able to:

  • Write and compose computations you want to run, before actually running them.

  • Design an error handling strategy for your application, taking side-effects into consideration.

  • Increase the parallelism and concurrency of your programs without the need to handle low-level details.

  • Use and compose resources that need to be released (connections, io streams, etc.) in an elegant manner.

  • Handle complex scenarios involving concurent shared state and thread communication by using purely functional primitives.

Hopefully, you will also have some fun along way.

Enroll now

What's inside

Syllabus

Introduction
Setting up environment
How to take this course
Course files
Read more
Understand what an effect is, and the different types of effects that are present in programming.
Referential transparency
Id generator
Optionality
State
Error handling
Printing to console
Writing to disk
Referentially transparent IO
Definitions and clarifications
Effects Quiz
Use the IO monad to compose side effectul computations
Intro
Basic usage
IOApp
Exercise
IO Monad Quiz
Design an error handling strategy leveraging IO, Validated, Either and Option.
Setting up API example
Validating inputs with Validated
Modeling domain errors with Either
Loading accounts with a Repository
Adding business logic with a Service
Combining logic into the final Controller
Testing
Ignoring Fatal Errors
Error Handling Quiz
Implement computations that run concurrently and/or in parallel by using methods such as parMapN, parTraverse and race.
ParMapN
ParTraverse
Race
Concurrency and Parallelism Quiz
Acquire, use and release resources (file writers, http clients, etc.) safely and without leaks.
Intro - Bracket
Writing to files with bracket
Intro - Resource
Copying and encrypting files with Resource
Resource Safety Quiz
Adapt legacy code that uses Future to using IO
Transforming a Future by blocking
Avoiding blocking with async_
Using fromFuture for conciseness
Running on different thread pools with evalOn
Asynchronous Computations Quiz
Apply memoization in order to avoid unnecessary re-running of computations
Setting up templates example
Loading templates eagerly
Loading templates on error only
Memoizing templates
Memoization Quiz
Use the time-related methods realTime and monotonic, understanding their differences.
Handling token expirations with realTime
Measuring how long computations run with monotonic
Time Quiz
Use the Ref primitive to safely share state in concurrent programs.
Loading customers
Storing the logs in a Ref
Using one Ref per customer
Refs Quiz
Use Deferred for communication between two concurrent processes
Showing items in a GUI
Adding parallelism with parMapN
Communicating processes with Deferred
Adding error handling
Deferred Quiz
Implement basic queue-based workflows by leveraging the Queue data structure from cats-effect.
Processing events with queues
Queue Quiz
Choose the correct thread pool to use based on the type of computation.
Types of Thread Pools
Work stealing pools
Cached Unbounded Pools
Execution contexts
Choosing the correct thread pool
Using compute and blocking pools
Thread Pools Quiz

Save this course

Save Functional effect handling in Scala with Cats Effect to your list so you can find it easily later:
Save

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Functional effect handling in Scala with Cats Effect with these activities:
Review Monads
Solidify your understanding of monads, a core concept in functional programming, to better grasp the IO monad used in Cats Effect.
Show steps
  • Read introductory materials on monads.
  • Work through examples of monads in Scala.
  • Relate monads to the concept of sequencing computations.
Read 'Scala with Cats'
Gain a deeper understanding of the underlying functional programming principles used in Cats Effect by working through 'Scala with Cats'.
Show steps
  • Work through the exercises in 'Scala with Cats'.
  • Relate the concepts to the Cats Effect library.
  • Focus on the type classes covered in the book.
Read 'Functional and Reactive Domain Modeling'
Deepen your understanding of functional domain modeling principles, which are essential for designing robust applications with Cats Effect.
Show steps
  • Read the book, focusing on domain modeling chapters.
  • Relate the concepts to the Cats Effect library.
  • Consider how to apply these principles in your projects.
Four other activities
Expand to see all activities and additional details
Show all seven activities
Write a blog post on error handling in Cats Effect
Solidify your understanding of error handling strategies by explaining them to others in a blog post.
Show steps
  • Review the error handling section of the course.
  • Write a blog post explaining different error handling techniques.
  • Include code examples and explanations.
  • Publish the blog post online.
Implement Concurrent Data Structures
Practice implementing concurrent data structures like queues and refs to reinforce your understanding of how they work under the hood.
Show steps
  • Implement a simple concurrent queue using `Ref`.
  • Implement a basic concurrent counter using `Ref`.
  • Test the data structures for thread safety.
Build a simple rate limiter using Cats Effect
Apply your knowledge of concurrency and resource management to build a practical rate limiter application.
Show steps
  • Design the rate limiter's architecture.
  • Implement the rate limiter using Cats Effect primitives.
  • Test the rate limiter for correctness and performance.
Contribute to Cats Effect
Deepen your understanding of Cats Effect by contributing to the open-source project.
Show steps
  • Browse the Cats Effect issue tracker on GitHub.
  • Identify a bug fix or feature enhancement to work on.
  • Submit a pull request with your changes.

Career center

Learners who complete Functional effect handling in Scala with Cats Effect will develop knowledge and skills that may be useful to these careers:
Scala Developer
A Scala developer specializes in building applications using the Scala programming language. Since this course focuses on functional effect handling in Scala with Cats Effect, it is directly relevant. This course is designed to improve your proficiency with Scala, particularly in the context of functional programming. Specific skills like using the IO monad, managing resources, and handling concurrency will be directly applicable to your daily work. You might get particular use out of the quizzes.
Concurrency Engineer
A concurrency engineer specializes in designing and implementing concurrent systems. This course is extremely useful, since it focuses on concurrency and parallelism using Cats Effect. You will learn practical techniques for managing shared state, handling errors, and optimizing performance in concurrent applications. The sections on Ref, Deferred, Queue, and thread pools are particularly relevant. You will want to practice with ParMapN and ParTraverse as well.
Functional Programmer
A functional programmer embraces functional programming principles to build software. This course emphasizes functional effect handling, making it highly relevant to this role. The knowledge of Cats Effect and the IO monad will allow you to manage side effects and build composable, testable code. The sections on error handling, resource management, and concurrency are essential for any functional programmer, as the course will show you how to increase the parallelism and concurrency of your programs without the need to handle low level details.
Backend Developer
A backend developer focuses on the server side of applications, including databases and APIs. This course's exploration of functional programming techniques for managing side effects is highly relevant. As a backend developer, you will likely encounter tasks requiring concurrency and resource management, both of which are covered in detail. The course section on error handling with IO, Validated, Either and Option will be extremely useful for creating robust APIs. Also, using bracket to write to files can allow you to build more reliable applications.
Software Engineer
A software engineer develops and maintains software systems. This course emphasizes separating program description from execution, which aligns with the principles of building robust and maintainable software. In this role, you might build concurrent and parallel applications. Concepts covered in the course, such as using the Cats Effect library and managing resources safely, directly translate to building reliable and scalable software. The section on choosing the correct thread pool to use based on the type of computation will be particularly helpful for designing efficient systems.
Application Developer
An application developer is responsible for designing, coding, and testing applications. This course emphasizes error handling and concurrency, both crucial for building resilient applications. Understanding how to use the IO monad to compose side-effectful computations, as taught in this course, helps you manage complexity when building applications. You may find the section on adapting legacy code with Future to using IO to be particularly beneficial for integrating with older systems, as well as the lesson on using Ref to safely share state in concurrent programs.
Software Architect
A software architect designs the high-level structure of software systems. This course emphasizes separating program description from execution, which is a key principle in architectural design. The techniques for managing side effects, concurrency, and resource management covered in this course will be invaluable for designing robust and scalable systems. The sections on concurrency, time, and choosing thread pools can be especially beneficial. Success as a software architect requires understanding of the tools taught by the course.
Systems Architect
A systems architect designs the structure and organization of software systems. This course emphasizes separating program description from execution, which is a crucial aspect of designing complex systems. This course helps build a foundation for creating scalable and resilient architectures. The course's exploration of concurrency, resource management, and error handling will be invaluable when making architectural decisions. You might want to pay special attention to the sections on thread pools and managing concurrent shared state with Ref.
Technical Lead
A technical lead guides a team of developers and makes technical decisions. This course emphasizes functional programming techniques for managing side effects and concurrency, which are crucial for leading complex software projects. The course can help you make informed decisions about how to structure code and handle errors effectively. The sections on error handling, concurrency, and resource management provide a solid base for leading technical discussions and setting best practices. You might want to look into the lessons involving Queue.
Full-Stack Developer
A full stack developer works on both the front end and back end of web applications. The course's emphasis on managing side effects can be useful when building predictable user interfaces and robust APIs. This functional programming course can help you manage the complexity of full stack projects. The sections on building APIs, handling concurrency, and managing resources can be particularly helpful. The lesson on using fromFuture for conciseness can result in more readable frontends.
Data Engineer
A data engineer builds and maintains data pipelines. Functional programming concepts, particularly dealing with effects, can be beneficial when building reliable data processing systems. This course emphasizes error handling and concurrency, which can be useful when working with large datasets. The use of IO monads for managing side effects, covered in this course, can also be useful when interacting with external data sources. You may find the sections on memoization and asynchronous computations to be particularly applicable.
Library Developer
A library developer creates reusable components for other developers to use. This course may be useful by providing insights into building robust and composable libraries using functional programming principles. Understanding how to manage side effects, handle errors, and provide concurrency can lead to more reliable and user-friendly libraries. Learning how to implement basic queue based workflows may also be useful. The course's lessons on memoization and Resource can be quite helpful.
Cloud Engineer
A cloud engineer manages and maintains cloud infrastructure. This course may be useful due to its coverage of concurrency, parallelism, and resource management, which are essential in cloud environments. Functional programming principles such as isolating side effects can aid in building more predictable cloud applications. The course section on choosing the correct thread pool to use based on the type of computation might be useful for optimizing performance in cloud deployments. Additionally, the lesson on using Resource to copy and encrypt files can help you build more secure applications.
DevOps Engineer
A DevOps engineer automates and streamlines the software development lifecycle. This course may be useful by providing insights into managing complex systems with functional programming techniques. Understanding how to handle effects and compose computations can lead to more predictable deployments. The sections on resource management and concurrency may be particularly relevant for managing infrastructure as code. Also, the lesson on using Deferred for communication between two concurrent processes may be useful.
Language Designer
A language designer creates and evolves programming languages. This course may be useful since it provides a deep dive into effect handling within the Scala language and the Cats Effect library. Understanding how these features are implemented and used can inform the design of new language features or improvements to existing ones. A deep dive into choices made can help one learn practical tools for programming language implementation. Topics such as Referential Transparency (RT) and thread pools can be relevant.

Reading list

We've selected two books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Functional effect handling in Scala with Cats Effect.
Provides a gentle introduction to category theory and functional programming concepts in Scala, which are foundational for understanding Cats Effect. It covers essential type classes like Functor, Applicative, and Monad. This book is helpful for those who are new to functional programming or want a refresher on the underlying theory. It provides a solid foundation for understanding the more advanced concepts in Cats Effect.
Provides a comprehensive guide to building robust and scalable systems using functional and reactive principles. It covers domain modeling techniques that are highly relevant to designing applications with Cats Effect. While not strictly about Cats Effect, it provides a broader context for understanding the design choices behind the library. This book is useful for those who want to understand the bigger picture of functional system design.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser