
Learn to model and compose effects in scala using the catafalque library, describe effects before execution, design robust error handling, safe concurrency, and safe resource release.
Set up your Scala environment for functional effect handling with Cats Effect by creating a project, adding a build file, and configuring source and worksheet workflows.
Explore what effects are in functional programming and how to achieve referential transparency. Review common effects like optionality and state, and discuss side effects and handling strategies.
Explore referential transparency by comparing two implementations of a distance function between points, showing that inlining expressions yields the same result, five, through substitution.
Demonstrate an id generator with a counter and a next method that yields consecutive ids and assigns groups, then illustrate how inlining next breaks referential transparency, causing unexpected results.
Explore how optionality via the option type preserves referential transparency in Scala, contrasting nulls and exceptions with some/none, map, and getOrElse.
Explore state handling in functional Scala with Cats Effect, switching from a mutable map to a state monad to achieve preferentially transparent add, delete, and find operations.
Learn error handling in Scala with Cats Effect by implementing withdrawal with exceptions versus either, introducing insufficient balance error and left or right results to achieve preferentially transparent behavior.
Explore printing to console and referential transparency in a Scala course using an order with items and a discounted price, showing how computing total once versus twice affects console output.
Demonstrate how writing to disk as an effect affects referential transparency in Scala with Cats Effect, showing writes occur only on actual log calls.
Describe computations with an IO type, delay, and by-name parameters to keep code pure while deferring side effects like console output, databases, and networks to the program's execution boundary.
Learn referential transparency by distinguishing the main effect from side effects, and see how pure functions avoid side effects using optional, either, and IO monads in Scala with Cats Effect.
Explore a real io implementation with Cats Effect, focusing on delay, apply, and thunk. Learn how pure values and flatMap compose effects with the io runtime.
Master basic Cats Effect usage in Scala by modeling console io as computations, running with a runtime, and composing with flatMap and for-expressions, including forever and failure cases.
Discover how IOApp lets the framework run your program, avoiding unsafe run by overriding run with a main method and exit codes. See input and output handled automatically.
Implement the Echo Forever exercise in Scala with Cats Effect, producing an endless line of output and looping, using map with an exit code like success or the from method.
Explore error handling in the IO monad with a bank transfer example, distinguishing domain from technical errors and choosing accumulate versus fail-fast strategies using validated or either.
Explore setting up an api example in Scala with Cats Effect by implementing a post transfer flow, defining flash request and response, and testing with io.
Use the validated data type from the caps library to validate inputs, with string as the error type, implementing string-to-double and letters-or-digits account number checks.
Model the account with a withdrawal method that returns an either of account or domain error, including an insufficient balance error.
Implement a map-backed repository to fetch an account by number using an option, model side effects, and add a save method to persist accounts.
Implement a transfer service that locates accounts, withdraws and deposits funds, enforces a maximum balance, and saves updated accounts, handling domain errors with either.
Combine validation and error handling into the final controller for post transfer, validating accounts and amount, mapping domain results to http responses.
Practice writing tests that prepopulate a dummy repository, perform transfers, and verify updated balances. Explore error handling by simulating missing accounts, invalid inputs, and technical errors in Cats Effect.
Choose to recover only from non-fatal errors by using the non-fatal matcher, recovering from regulatory failures and returning 500, while fatal issues like out-of-memory remain uncaught.
Explore error handling in Scala with Cats Effect by implementing a text file word count, mapping errors to domain and technical failures, and testing with various failure modes.
Explore concurrency in scala with cats effect, using traverse and map with IO to build parallel operations and a race to fetch fastest quotes or images, cancelling the slower task.
Learn functional effect handling in scala with cats effect by building an IO-based image fetcher that combines HD and TV image results in parallel using parMapN.
Explore ParTraverse in Scala with Cats Effect by saving a list of people in parallel, compare with sequence and traverse, and observe faster results when operations are independent.
Compare and harness the race method in Cats Effect to race two image fetch streams, cancel the slower task, and select the faster result from HDP or TV sources.
Practice functional effect handling in Scala with Cats Effect by fetching quotes from two sources in parallel, extracting authors' ages, and computing the average age with traversals and fold.
Master resource safety in Scala with Cats Effect by using bracket to acquire, use, and release a file writer, encoding objects, writing contents, flushing, and closing on errors.
demonstrate safe file writing using bracket in scala with cats effect, ensuring the file writer closes even when errors occur, as an alternative to try/catch finally.
Explore resource safety in Scala with Cats Effect by using bracket and resource to safely acquire, compose, and release reader and writer while encrypting files.
Explore resource-based file copying and encryption, showing how to acquire and close readers and writers safely, maintain correct close order, and prevent leaks even on errors.
Exercise safe resource management in Scala with Cats Effect by creating connection and reader resources and composing them into a single http get service to ensure release.
Transform a synchronous future-based find into a non-blocking IO workflow using the current execution context and async to complete with right or left.
Transform a future by blocking to retrieve a person from a legacy API, choosing an execution context, and awaiting the result with a specified duration.
Avoid blocking by converting futures to io with async. Use an execution context and a callback, handle right and left outcomes, and run on io to combine operations.
Explore transforming from future to real using Mona's from future method for conciseness, and replace with IO from future to convert the future, showing similar behavior in tests.
Discover how to run an IO on a specific execution context using evalOn, override the default compute pool, and manage thread pools in functional effect handling with Cats Effect.
This exercise shows converting a callback-based find user into an IO.async-based approach, returning a user or an error. It demonstrates handling success and failure with right and left.
Explore memorization in functional effect handling with Cats Effect, caching loaded email templates to process multiple clients efficiently and handle errors without reloading templates.
Implement a long-running process to handle a list of clients by fetching email templates and sending targeted emails when errors such as negative balances or account expiry occur.
Explore loading templates eagerly and processing clients with traverse, handle errors by pattern matching, and simulate email sending in a functional effect setting with Cats Effect in Scala.
Optimize by loading templates only on error, avoiding unnecessary long running computations in the happy path, and assess race scenarios to ensure correct template loading, though challenges remain.
Introduce a memoized templates approach using IO of IO to load and cache email templates only when needed, improving efficiency for multiple errors and conditional sending.
Demonstrate functionally handling side effects by converting a currency balance calculator to use lazy evaluation and caching for exchange rates, fetching rates only when needed and in parallel where possible.
Explore how Cats Effect IO handles time in Scala, implementing token expiry with referentially transparent methods, using IO real time and monotonic clocks to measure elapsed time.
Use realTime to check token expiration by comparing the token's expiration minutes with the current time, producing a boolean and testing expired and future cases.
Measure how long computations run with a monotonic clock and real time, capturing start and end times to compute duration and convert to minutes in Scala with Cats Effect.
Implement two time functions: reuse real time logic to compute tomorrow as today plus one day, yielding a local daytime from a duration and an instant via a factory method.
Explore handling concurrent customer data loading and logging with Cats Effect, using Ref for atomic updates and per-customer refs to group logs.
Learn how to load a customer and related data (name, accounts, activities, purchases) in parallel using Cats Effect, enabling concurrent loading and logging in a functional Scala workflow.
Parallel load all customers, storing the resulting locks in a Cats Effect ref. Update the ref atomically to group locks by customer and print the loaded customers.
Use one ref per customer to keep each customer's logs isolated during parallel loads, delivering correctness and improved performance.
Implement a recursive exercise that traverses a user hierarchy, including friends, in parallel, using a cats effect ref to hold the current oldest user and update it atomically with io.
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!