Learning Functional Programming

Book description

Learn how to think and write code like a functional programmer. With this practical guide, software developers familiar with object-oriented programming will dive into the core concepts of functional programming and learn how to use both functional and OOP features together on large or complex software projects.

Author Jack Widman uses samples from Java, Python, C#, Scala, and JavaScript to help you gain a new perspective and a set of tools for managing the complexity in your problem domain. You'll be able to write code that's simpler, reusable, easier to test and modify, and more consistently correct. This book also shows you how to use patterns from category theory to help bridge the gap between OOP and functional programming.

  • Learn functional programming fundamentals and explore the way functional programmers approach problems
  • Understand how FP differs from object-oriented and imperative programming
  • Use a set of practical, applicable design patterns that model reality in a functional way
  • Learn how to incorporate FP and OOP features into software projects
  • Apply functional design patterns appropriately and use them to write correct, robust, and easily modifiable code

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Who Should Use This Book?
    2. How The Book Is Organized
    3. Conventions Used in This Book
    4. O’Reilly Online Learning
    5. How to Contact Us
  2. 1. What Is Functional Programming?
    1. Immutability
    2. Referential Transparency
    3. Higher Order Functions
    4. Lazy Evaluation
    5. Thinking Like a Functional Programmer
    6. The Benefits of FP
      1. FP Can Improve Productivity
      2. FP Is Fun!
      3. Scala
    7. Conclusion
  3. 2. Mathematical Preliminaries
    1. Set Theory
      1. Functions
      2. Kinds of Functions
    2. Computer Science Fundamentals
      1. Anonymous Functions
      2. Functions as First Class Objects
    3. Conclusion
  4. 3. Category Theory and Patterns
    1. Category Theory–Based Patterns
      1. A Brief History
      2. Objects and Morphisms
      3. An Example of a Category
      4. The Category Scal
      5. Functors
      6. Programming Language Formulation of a Functor
    2. The Patterns
      1. The Functor Pattern
      2. Monoids
      3. Natural Transformations
      4. Monads
    3. Conclusion
  5. 4. Functional Data Structures
    1. The Option Data Structure
    2. The Try Data Structure
    3. The Either Data Structure
    4. Higher Order Functions
    5. Monads in for Comprehensions in Scala
    6. Traditional Data Structures
      1. Immutability and History
      2. Laziness
    7. Conclusion
  6. 5. More on Immutability
    1. Mutable and Immutable Variables
    2. Recursion
      1. A Linked List Example
    3. Tail Recursion
    4. More Examples of the Power of fold in Scala
    5. A Connection Between fold and Monoids
    6. More with Higher Order Functions
      1. From map to flatMap
    7. Conclusion
  7. 6. Questions of Concurrency
    1. Streams
    2. Akka Streams
      1. Source
      2. Flow
      3. Sink
    3. More on Streams
    4. FS2: Functional Streams for Scala
    5. Conclusion
  8. 7. Where to from Here?
    1. Taking the Pure Route
      1. The IO Monad
      2. Taking the Middle Route
      3. JVM Languages
      4. .NET Languages
      5. Type Classes
    2. Conclusion
  9. A. Scala
    1. Assumptions
    2. Overview
    3. var and val
    4. Classes and Objects
    5. Functions
      1. Functions that Return Functions
    6. Case Classes
      1. Declaring Functions
      2. Currying
      3. Anonymous Functions
      4. Higher Order Functions
      5. Pattern Matching
      6. Traits
      7. Distinguishing Abstract Classes and Traits
      8. Lazy Evaluation
      9. Type Parameters
      10. The Option Type
      11. Future
      12. Some Key Higher Order Functions
      13. Some Other Important Higher Order Functions
    7. Conclusion
  10. Index
  11. About the Author

Product information

  • Title: Learning Functional Programming
  • Author(s): Jack Widman
  • Release date: August 2022
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098111755