Book : https://www.manning.com/books/functional-programming-in-scala
Code has been organized in packages according to the chapter in which the concept or exercise was introduced.
The repo contains solved exercises, code from the book examples or original code that exemplifies the concept presented.
Unit tests are used to verify and run the implementation (todo some code needs to be migrated to unit tests)
Bellow is a useful listing to help navigate the repo and revisit parts by jumping straight to the code from here:
-
Introduction to functional programming
- What is functional programming?
- Getting started with functional programming in Scala
- Functional data structures
- Implementing a List
- Creating a List literal using variadic apply
- Pattern matching - implement list operations: tail, setHead, sum, product, drop, append
- Pattern matching deeper in the type structure
- Helping type inference using optional parameter lists
- HOF: foldRight - sum, product, length, append, concat - generalized implementations
- HOF: foldLeft - sum, product, length, reverse - generalized implementations
- foldLeft implemented with foldRight
- foldRight implemented with foldLeft
- Naive map, filter, zipWith
- HOF: map, flatMap, filter, zipWith
- Scala Collections library examples
- hasSubsequence: Loss of efficiency when assembling list functions from simpler components
- Implementing a Tree
- Operations on tree: size, max, depth, map
- Fold on Tree: Using HOF to implement tree operations
- Handling errors without exceptions
- Strictness and laziness
- Purely functional state
- Making stateful APIs pure, with simple next state return
- Naive composition of state generating functions
- Generalizing using State transition type
- Using combinators to compose State transitions
- flatMap: A more powerful combinator
- Generalizing functions: unit, map, map2 flatMap, sequence for a State object
- Implementing a FSM (Candy Machine) using State object
-
Functional design and combinator libraries
- Purely functional parallelism
- Implementing a data type for parallel computations
- Using Par type to compute sum in parallel
- Making map2 respect timeouts on Future
- Combinators: parMap, sequence, sequenceBalanced
- Additional combinators: foldRight, concat, flatMap, filter, parFilter
- Operation on sequences in parallel using Par operations: sum, max, sort
- Purely functional parallelism