Query Composition using Functional Programming Techniques in C# 3.0
2007-04-13 12:17
615 查看
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.
Refactors the previously introduced query using a pure function. The resulting query is easier to read.
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>.
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.
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.
17. Conclusion
Final thoughts about functional programming.
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.
Refactors the previously introduced query using a pure function. The resulting query is easier to read.
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>.
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.
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.
17. Conclusion
Final thoughts about functional programming.
相关文章推荐
- 【黑马程序员】Object-Oriented Programming Techniques in C#
- [Ramda] Convert a QueryString to an Object using Function Composition in Ramda
- Programming Windows Workflow Foundation: Practical WF Techniques and Examples using XAML and C#
- Asynchronous Programming in C# 5.0 using async and await
- GDI+ Programming: Creating Custom Controls Using C#
- Introduction to ASP.NET Web Programming Using the Razor Syntax (C#)
- 《C#3.0面向对象编程 Beginning C# 3.0: An Introduction to Object Oriented Programming》推荐给编程入门者(初中生也可读)
- The Ruby Way, Second Edition: Solutions and Techniques in Ruby, Programming (Paperback) 2nd.Edition.Oct.2006.eBook-BBL
- Creating a Web Control with an Expandable Property in the Designer by Using C#.
- 下载《GDI+ Programming:Creating Custom Controls Using C#》中文版
- C#控制台进度条(Programming Progress bar in C# Consle application)
- parallel programming. this causual litery nots represents my recent progress in parallel programming in c#.It`s interesting.
- The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
- [转载]Hello World Outlook Add-In using C#
- Functional Programming in Scala第二章练习
- Convert objects to JSON in C# using JavaScriptSerializer
- Interception and Interceptors in C# (Aspect oriented programming) 转载
- Hello World Outlook Add-In using C#
- New Features in C# 3.0
- Set Data Format in Excel Using POI 3.0(XSSF/HSSF)