Permalink
Browse files

folding

  • Loading branch information...
1 parent a4f0e65 commit a5610ef3e1162fbe2f5b0667cc63c95a63da593d @raganwald raganwald committed Feb 16, 2013
Showing with 6 additions and 2 deletions.
  1. +3 −1 2013/02/turtles-and-iterators.js.md
  2. +3 −1 2013/02/turtles-and-iterators.md
@@ -229,7 +229,7 @@ We've successfully separated the issue of what one does with data from how one t
**folding**
-Just as pure functional programmers love to talk monads, newcomers to functional programming in multi-paradigm languages often drool over [folding](https://en.wikipedia.org/wiki/Fold_(higher-order_function)) a/k/a mapping/injecting/reducing. We're just a level of abstraction away:
+Just as pure functional programmers love to talk monads, newcomers to functional programming in multi-paradigm languages often drool over [folding] a/k/a mapping/injecting/reducing. We're just a level of abstraction away:
```javascript
function fold (iter, binaryFn, seed) {
@@ -255,6 +255,8 @@ foldingSum(LeafIterator([1, [2, [3, 4]], [5]]));
Fold turns an iterator over a finite data structure into an accumulator. And once again, it works with any data structure. You don't need a different kind of fold for each kind of data structure you use.
+[folding]: https://en.wikipedia.org/wiki/Fold_(higher-order_function)
+
**unfolding and laziness**
Iterators are functions. When they iterate over an array or linked list, they are traversing something that is already there. But they could, in principle, manufacture the data as they go. Let's consider the simplest example:
@@ -164,7 +164,7 @@ We've successfully separated the issue of what one does with data from how one t
**folding**
-Just as pure functional programmers love to talk monads, newcomers to functional programming in multi-paradigm languages often drool over [folding](https://en.wikipedia.org/wiki/Fold_(higher-order_function)) a/k/a mapping/injecting/reducing. We're just a level of abstraction away:
+Just as pure functional programmers love to talk monads, newcomers to functional programming in multi-paradigm languages often drool over [folding] a/k/a mapping/injecting/reducing. We're just a level of abstraction away:
```coffeescript
fold = (iter, binaryFn, seed) ->
@@ -182,6 +182,8 @@ foldingSum LeafIterator [1, [2, [3, 4]], [5]]
Fold turns an iterator over a finite data structure into an accumulator. And once again, it works with any data structure. You don't need a different kind of fold for each kind of data structure you use.
+[folding]: https://en.wikipedia.org/wiki/Fold_(higher-order_function)
+
**unfolding and laziness**
Iterators are functions. When they iterate over an array or linked list, they are traversing something that is already there. But they could, in principle, manufacture the data as they go. Let's consider the simplest example:

0 comments on commit a5610ef

Please sign in to comment.