getify / Functional-Light-JS

Pragmatic, balanced FP in JavaScript. @FLJSBook on twitter.
http://FLJSBook.com
Other
16.6k stars 1.95k forks source link

`result(..)` should be `result` ? #100

Closed JoeHetfield closed 7 years ago

JoeHetfield commented 7 years ago

Ch4, line 317:

Notice that the reduce(..) looping happens each time the final composed(..) function is run, and that each intermediate result(..) is passed along to the next iteration as the input to the next call.

and the code snippet in question:

function compose(...fns) { return function composed(result){ return fns.reverse().reduce( function reducer(result,fn){ return fn( result ); }, result ); }; }

The result was passed as the initial value of reduction, and will accumulate the result of every iteration. It could be a function, but there is no sign that it had been executed. So I think the result(..) in the text should be result.

getify commented 7 years ago

Composition is always working on functions so result would always be a function.