Chapter 4. Toward modular, reusable code

 

This chapter covers

  • Comparing function chains and pipelines
  • Introducing the Ramda.js functional library
  • Exploring the concepts of currying, partial application, and function binding
  • Creating modular programs with functional composition
  • Enhancing your program’s flow with function combinators

A complex system that works is invariably found to have evolved from a simple system that worked.

John Gall, The Systems Bible (General Systemantics Press, 2012)

Modularity is one of the most important qualities of large software projects; it represents the degree to which programs can be separated into smaller, independent parts. Modular programs posses the distinct quality that their meaning can be derived from the meaning of their constituent parts. These parts (or subprograms) become reusable components that can be incorporated as a whole or in pieces into other systems. This makes your code more maintainable and readable while making you more productive. As a simple use case, think of how Unix shell programs are written:

tr 'A-Z' 'a-z' <words.in | uniq | sort

4.1. Method chains vs. function pipelines

4.2. Requirements for compatible functions

4.3. Curried function evaluation

4.4. Partial application and parameter binding

4.5. Composing function pipelines

4.6. Managing control flow with functional combinators

4.7. Summary

sitemap