Skip to content

Commit

Permalink
apA: starting on 'transducing' appendix
Browse files Browse the repository at this point in the history
  • Loading branch information
getify committed Feb 1, 2017
1 parent 8a31710 commit b15af5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ But I want you to be able to apply some of the fundamentals of FP to your JavaSc
* [Chapter 9: Recursion](ch9.md)
* [Chapter 10: Functional Async](ch10.md)
* [Chapter 11: Putting It All together](ch11.md)
* Appendix A: Transducing
* [Appendix A: Transducing](apA.md)
* Appendix B: The Humble Monad
* Appendix C: FP Libraries

Expand Down
15 changes: 15 additions & 0 deletions apA.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Functional-Light JavaScript
# Appendix A: Transducing

Transducing means transforming with reduction.

Example:

```js
function compose(fn2,fn1) {
return function composed(...args){
Expand Down Expand Up @@ -44,4 +51,12 @@ words
);
```

## Summary

To transduce means to transform + reduce.

More practically, we use transducing to compose adjacent `map(..)`, `filter(..)`, and `reduce(..)` operations together. We accomplish this by first expressing `map(..)`s and `filter(..)`s as `reduce(..)`s.

A transducer is the composition of multiple adjacent reducers. Composing reducers can't just be done naively with `compose(..)` because of the multiple-parameters signature of a reducer. So we have to abstract the combination step -- taking two values and combining them into one -- so it can be parameterized.

Transducing primarily improves performance, which is especially obvious if used on a lazy sequence (async observable). But more broadly, transducing is how we express a more declarative composition of functions that would otherwise not be composable.

0 comments on commit b15af5c

Please sign in to comment.