Via: http://blogs.msdn.com/ericwhite/pages/FP-Tutorial.aspx

QuoteThis is a tutorial on using Functional Programming (FP) techniques for constructing LINQ queries. It is certainly possible to write simple LINQ queries without using these techniques, but as soon as you start writing more complicated queries, you need to understand these techniques.
1. Introduction to the FP Tutorial

Introduces functional programming, mentions some of the core ideas, and the main hurdle (lazy evaluation) that users of LINQ will have to jump.

2. What this Tutorial Covers

Gives a quick overview of what the tutorial covers.  

3. Quick Intro to Query Expressions

Capsule summary of query expressions and explicit notation.

4. Lambda Expressions

Introduction to lambda expressions, their syntax, and their semantics. Lambda expressions are one of the key tools that you will use when doing functional programming.

5. Extension Methods

 Introduction to extension methods, and their applicability to functional programming.

6. Local Variable Type Inference

Anonymous types are key to FP, and in certain circumstances, to use anonymous types, you must use local variable type inference.

7. Object and Collection Initializers

To use anonymous types, you must use object and collection initializers. This introduces them.

8. Tuples and Anonymous Types

Tuples are important for creating intermediate values (and sometimes final results) of queries. This introduces tuples as implemented via anonymous types. 

9. The Yield Contextual Keyword

Yield blocks are the foundation on which lazy evaluation is based. Yield blocks were introduced to C# in version 2.0. 

10. Lazy Evaluation

This introduces and discusses what may be the most difficult hurdle that OO programmers must get over when using LINQ.

11. Aggregation

Aggregation is a core tool that you will use to develop results when using FP. 

12. Programming in a Functional Style

Introduces the idea of declarative programming (vs. imperative programming).

13. Procedural Analogs

Presents an analog to the switch procedural construct.

14. Pure Functions

Refactoring in FP consists of creation of pure functions. This defines pure functions and tells why you want to use them. 

15. Parsing WordML

This introduces our main example that we'll use in this tutorial. This example pulls together all of the previously introduced topics, including lambda expressions, extension methods, tuples (including type inference and object initializers), lazy evaluation, aggregation, and pure functions.

15.1 The Word Document to Parse 

This topic contains the Word document that we'll parse using FP techniques.

15.2 Retrieving the Paragraphs

Develops a query that returns all of the paragraphs in a Word document. Creates an intermediate result using an anonymous type.

15.3 Refactoring using a Pure Function

Refactors the previously introduced query using a pure function. The resulting query is easier to read.

15.4 Retrieving the Text of the Paragraphs

Modifies the query to retrieve the text of each of the paragraphs. Adds the text to the tuple.

15.5 Separating Out the Code and Comments

Modifies the query to determine whether a paragraph is code or comment, or anything else.

15.6 Retrieving the Two Code/Comment Groups

Introduces a new query operator, GroupOnChange, implemented as an extension method on IEnumerable<T>.

15.7 Filtering Out the Groups that we Don't Want

Modifies the query to retrieve just the groups that we want.

15.8 The Final Results

Modifies the query to retrieve exactly what we want. This is the end target of this example.

15.9 Complete Listing of ParseWordML

Contains the complete listing of our example.

16. Overview of a Functional Transform

Introduces the idea of doing transformations in a functional programming style. Contains the code for the transformation.

16.1 PurchaseOrders.xml

Contains the source XML document for our transformation.

17. Conclusion

Final thoughts about functional programming.


Posted on 2007-04-13 12:17 Adrian H. 阅读(...) 评论(...) 编辑 收藏