O'Reilly logo

Professional F# 2.0 by Richard Minerich, Talbott Crowell, Aaron C. Erickson, Ted Neward

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 16. List Processing

WHAT'S IN THIS CHAPTER?

  • Understanding collection processing abstractions

  • Subsetting collections

  • Transforming collections

  • Understanding accumulators

  • 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.

COLLECTION ABSTRACTIONS

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required