8

Readable Function Composition with Fluent Programming

In this chapter, we are going to look at different methods for chaining functions in functional programming. The end goal here is to write code that is easier to read and takes up less visual space. We will look at three ways to achieve this:

  • First, we will take a look at how we can use type aliases to attach methods to container types, allowing us to create chained functions with the familiar dot notation.
  • We’ll then discuss lazy versus eager code evaluation.
  • Next, we will take a look at continuation-passing style (CPS) programming. In CPS, we will use higher-order functions to create a control flow without our functions.
  • We’ll also discuss the trade-offs in each approach.

Technical ...

Get Functional Programming in Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.