learning-react icon indicating copy to clipboard operation
learning-react copied to clipboard

Chapter 3 - Compose function

Open jamespavett opened this issue 4 years ago • 0 comments

Hello, not really an issue but something I am just unsure about.

const compose = (...fns) =>
      (arg) =>
      fns.reduce(
        (composed, f) => f(composed),
        arg
    )

In chapter 3 compose is shown to use the array reduce function, along with being discussed that way in the next.

Doesn't this differ from tradition convention though. Using reduce is traditionally a pipe as it operating left-to-right. The name compose is usually used for a right-to-left pipe where reduceRight is used. Just including the following link as an example of what I mean: https://aparnajoshi.netlify.app/javascript-pipe-and-compose-functions

Obviously is this book compose is being used for reduce operations acting left-to-right.

jamespavett avatar Jan 21 '22 04:01 jamespavett