Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

folding

  • Loading branch information...
commit a5610ef3e1162fbe2f5b0667cc63c95a63da593d 1 parent a4f0e65
Reg Braithwaite raganwald authored
4 2013/02/turtles-and-iterators.js.md
View
@@ -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:
4 2013/02/turtles-and-iterators.md
View
@@ -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:
Please sign in to comment.
Something went wrong with that request. Please try again.