Chapter 16. List Processing
WHAT'S IN THIS CHAPTER?
Understanding collection processing abstractions
Leveraging scanning and folding
Functional programming in F# really shines when dealing with the processing of linear data structures. A linear data structure is any in which traversal of every node is linear in nature. That is, each element of the data structure can be visited sequentially in terms a previous element. Lists and sequences fit into this category. Arrays do partially as they are often accessed in this way.
The reason F# is particularly suited to this is primarily the great number of constructs provided by the language framework. F# provides a copious number of functions for the manipulation and analysis of each of its data structures. Although large in number, the elegance and simplicity provided by these functions is one of the fundamental reasons F# excels at list processing.
There are many ways to think about processing the elements of the list. You might even view much of the history of programming to be the history of linear data set processing. First, consider the lineage of imperative list iteration.
At the lowest level there is the humble JMP instruction from which you must construct your list from scratch; in higher level languages this is analogous to the
goto statement. At a slightly higher level of abstraction there is the
while statement which, in exchange for some ...