Chapter 12. Sequence expressions and alternative workflows
This chapter covers
- Processing and generating sequences of values
- Working with F# sequence expressions
- Understanding monads and LINQ expressions
- Implementing F# computation expressions
Before we can start talking about sequence expressions, you must know what a sequence is. This is another F# term that comes from mathematics, where a sequence is an ordered list containing a possibly infinite number of elements. Don’t worry if that all sounds a bit abstract; you’re already familiar with the type that expresses the same idea in .NET: IEnumerable<T>.
The primary reason for having the IEnumerable<T> type in the .NET Framework is it gives us a unified way to work with collections of data such as arrays, dictionaries, mutable lists, and immutable F# lists. In F# we’ll be talking about sequences, because this is a more general term. A sequence can represent a finite number of elements coming from a collection, but it can be also generated dynamically and retrieved on an on-demand basis. You’ll learn that infinite sequences, which sound somewhat academic, can still be useful in real applications.