O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Becoming Functional

Book Description

If you have an imperative (and probably object-oriented) programming background, this hands-on book will guide you through the alien world of functional programming. Author Joshua Backfield begins slowly by showing you how to apply the most useful implementation concepts before taking you further into functional-style concepts and practices.

Table of Contents

  1. Preface
    1. Who Is This Book For?
    2. Math Notation Review
    3. Why Functional over Imperative?
    4. Why Functional Alongside OOP?
    5. Why Functional Programming Is Important
    6. Conventions Used in This Book
    7. Using Code Examples
    8. Safari® Books Online
    9. How to Contact Us
    10. Acknowledgments
  2. 1. Introduction
    1. Overview of Concepts in Functional Programming
      1. First-Class Functions
      2. Pure Functions
      3. Recursion
      4. Immutable Variables
      5. Nonstrict Evaluation
      6. Statements
      7. Pattern Matching
    2. Functional Programming and Concurrency
    3. Conclusion
  3. 2. First-Class Functions
    1. Introduction to XXY
    2. Functions as Objects
      1. Refactoring Using If-Else Structures
      2. Refactoring Using Function Objects to Extract Fields
    3. Anonymous Functions
      1. Lambda Functions
      2. Closures
    4. Higher-Order Functions
    5. Refactoring get Functions by Using Groovy
    6. Conclusion
  4. 3. Pure Functions
    1. Output Depends on Input
    2. Purifying Our Functions
    3. Side Effects
    4. Conclusion
      1. Making the Switch to Groovy
  5. 4. Immutable Variables
    1. Mutability
    2. Immutability
    3. Conclusion
  6. 5. Recursion
    1. An Introduction to Recursion
    2. Recursion
    3. Tail Recursion
    4. Refactoring Our countEnabledCustomersWithNoEnabledContacts Function
    5. Conclusion
      1. Introducing Scala
  7. 6. Strict and Nonstrict Evaluations
    1. Strict Evaluation
    2. Nonstrict (Lazy) Evaluation
    3. Laziness Can Create Problems
    4. Conclusion
  8. 7. Statements
    1. Taking the Plunge
    2. Simple Statements
    3. Block Statements
    4. Everything Is a Statement
    5. Conclusion
  9. 8. Pattern Matching
    1. Simple Matches
    2. Simple Patterns
    3. Extracting Lists
    4. Extracting Objects
    5. Converting to Pattern Matches
    6. Conclusion
  10. 9. Functional OOP
    1. Static Encapsulation
    2. Objects As Containers
    3. Code as Data
    4. Conclusion
  11. 10. Conclusion
    1. From Imperative to Functional
      1. Introduce Higher-Order Functions
      2. Convert Existing Methods into Pure Functions
      3. Convert Loops to Tail/Recursive-Tail Methods
      4. Convert Mutable Variables into Immutable Variables
      5. What Next?
    2. New Design Patterns
      1. Message Passing for Concurrency
      2. The Option Pattern (Extension of Null Object Pattern)
      3. Object to Singleton Method Purity
    3. Putting It All Together
    4. Conclusion
  12. Index
  13. Colophon
  14. Copyright