This chapter is on what I call fold-vectorization. In some languages, it’s called reduce, though the concept is the same. Fold implements binary iterated function application, where elements of a sequence are passed along with an accumulator to a function. This process repeats such that each successive element is paired with the previous result of the function application. The version of fold discussed in the book appears in my lambda.tools package.

There are numerous applications of fold that span basic algebraic functions, such as the cumulative sum and product, to applying the derivative, to implementing Markov Chains. This chapter first delves into the mathematical motivation for fold. It then returns to the ebola.sitrep package and discusses the use of fold for applying transformations to data frames. Some examples work off the parsed file, which resides in the data directory of the project. The chapter finishes up by reviewing some methods of numerical analysis related to function approximation and series to further illustrate the use of fold in implementing mathematical relationships.

As usual, feedback and comments are welcome. I’m mostly interested in conceptual issues, although grammatical and typographical issues are also fair game.

Rowe – Modeling Data With Functional Programming Chs1-4

### Like this:

Like Loading...

*Related*

myschizobuddy

said:will there be a chapter on how to use functional programming to build shiny apps?

LikeLike

K. Alan Bates

said:While I thoroughly enjoy the content that you have published here (for free!!) I find your example through 1.2(Starting at Figure 1.1) to be somewhat perplexing. I don’t understand your purpose behind attempting to juxtapose an explicit object-oriented structure to an invocation of apply() and speaking to a comparison of the complexity of their implementations. You chose the wrong pattern for representing how this task would be accomplished using OOP tactics (You chose Strategy rather than Command) and you made zero mention of the internal structure of apply() so -as a reader- I’m curious to know how you expect that to be taken as an apples-to-apples comparison that should persuade someone to choose “implicit apply(…)” over “explicit aggregate_iris(…)” Also, the object-oriented code that you have written for your comparison is trivial to implement and I would expect to take no longer than 10 minutes to prepare (with 5 minutes to grab some coffee.) I just don’t understand how that is supposed to persuade; that code is exceptionally simple to all but neophytes.

I appreciate gaining a bit of insight into why you structured this example in such a way. I feel that you are comparing “apply(magic)” to a straw man and saying “See; wasn’t apply() easier?” and I’m nearly certain you have something better to say than that.

LikeLike