You are previewing Thinking in LINQ: Harnessing the power of functional programing in .NET applications.
O'Reilly logo
Thinking in LINQ: Harnessing the power of functional programing in .NET applications

Book Description

LINQ draws on principles of functional programming and represents a paradigm shift for developers used to an imperative/object oriented programming style. Thinking in LINQ explains the benefits of functional programming built into LINQ, allowing developers to use these techniques write more efficient and concise data-intensive applications.

While other books on the subject merely scratch the surface in terms of problem solving using LINQ, Thinking in LINQ shows readers how use functional programming techniques to solve common every-day problems as well as more complex problems using LINQ’s features.

LINQ lets you write code that resembles natural language and is easier to debug compared to traditional loops and branching statements. The purpose of a well written LINQ Query will be immediately evident unlike the looping construct so commonly used in traditional programming. LINQ operators can be used in unison to orchestrate a solution for complex real world problems.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Thinking Functionally
    1. 1-1. Understanding Functional Programming
    2. 1-2. Using Func<> in C# to Represent Functions
    3. 1-3. Using Various Types of Functions
      1. Generator Functions
      2. Statistical Functions
      3. Projector Functions
      4. Filters
    4. 1-4. Understanding the Benefits of Functional Programming
      1. Composability
      2. Lazy Evaluation
      3. Immutability
      4. Parallelizable
      5. Declarative
    5. 1-5. Getting LINQPad
  12. Chapter 2: Series Generation
    1. 2-1. Math and Statistics: Finding the Dot Product of Two Vectors
      1. Problem
      2. Solution
      3. How It Works
    2. 2-2. Math and Statistics: Generating Pythagorean Triples
      1. Problem
      2. Solution
      3. How It Works
    3. 2-3. Math and Statistics: Finding a Weighted Sum
      1. Problem
      2. Solution
      3. How It Works
    4. 2-4. Math and Statistics: Finding the Percentile for Each Element in an Array of Numbers
      1. Problem
      2. Solution
      3. How It Works
    5. 2-5. Math and Statistics: Finding the Dominator in an Array
      1. Problem
      2. Solution
      3. How It Works
    6. 2-6. Math and Statistics: Finding the Minimum Number of Currency Bills Required for a Given Amount
      1. Problem
      2. Solution
      3. How It Works
    7. 2-7. Math and Statistics: Finding Moving Averages
      1. Problem
      2. Solution
      3. How It Works
    8. 2-8. Math and Statistics: Finding a Cumulative Sum
      1. Problem
      2. Solution
      3. How It Works
    9. 2-9. Recursive Series and Patterns: Generating Recursive Structures by Using L-System Grammar
      1. Problem
      2. Solution
      3. How It Works
    10. 2-10. Recursive Series and Patterns Step-by-Step Growth of Algae
      1. Problem
      2. Solution
      3. How It Works
    11. 2-11. Recursive Series and Patterns: Generating Logo Commands to Draw a Koch Curve
      1. Problem
      2. Solution
      3. How It Works
    12. 2-12. Recursive Series and Patterns: Generating Logo Commands to Draw a Sierpinski Triangle
      1. Problem
      2. Solution
      3. How It Works
    13. 2-13. Recursive Series and Patterns: Generating Fibonacci Numbers Nonrecursively (Much Faster)
      1. Problem
      2. Solution
      3. How It Works
    14. 2-14. Recursive Series and Patterns: Generating Permutations
      1. Problem
      2. Solution
      3. How It Works
    15. 2-15. Recursive Series and Patterns: Generating a Power Set of a Given Set
      1. Problem
      2. Solution
      3. How It Works
    16. 2-16. Collections: Picking Every n th Element
      1. Problem
      2. Solution
      3. How It Works
    17. 2-17. Collections: Finding the Larger or Smaller of Several Sequences at Each Index
      1. Problem
      2. Solution
      3. How It Works
    18. 2-18. Number Theory: Generating Armstrong Numbers and Similar Number Sequences
      1. Problem
      2. Solution
      3. How It Works
    19. 2-19. Number Theory: Generating Pascal’s Triangle Nonrecursively
      1. Problem
      2. Solution
      3. How It Works
    20. 2-20. Game Design: Finding All Winning Paths in an Arbitrary Tic-Tac-Toe Board
      1. Problem
      2. Solution
      3. How It Works
    21. 2-21. Series in Game Design: Solving Go Figure
      1. Problem
      2. Solution
      3. How It Works
    22. 2-22. Miscellaneous Series: Finding Matching Pairs from Two Unsorted Collections
      1. Problem
      2. Solution
      3. How It Works
    23. 2-23. Miscellaneous Series: Using a Lookup-Based Approach
      1. Problem
      2. Solution
      3. How It Works
    24. 2-24. Miscellaneous Series: Solving the FizzBuzz Challenge in a LINQ One-Liner
      1. Problem
      2. Solution
      3. How It Works
    25. 2-25. Miscellaneous Series: Solving the FizzBuzz Challenge by Using Set Theory
      1. Problem
      2. Solution
      3. How It Works
    26. Summary
  13. Chapter 3: Text Processing
    1. 3-1. Simulating a T9 Word Suggestion
      1. Problem
      2. Solution
      3. How It Works
    2. 3-2. Simulating a Gesture Keyboard
      1. Problem
      2. Solution
      3. How It Works
    3. 3-3. Cloning Peter Norvig’s Spelling-Correction Algorithm
      1. Problem
      2. Solution
      3. How It Works
    4. 3-4. Reversing a Sentence Word by Word
      1. Problem
      2. Solution
      3. How It Works
    5. 3-5. Creating a Word Triangle
      1. Problem
      2. Solution
      3. How It Works
    6. 3-6. Finding Anagrams
      1. Problem
      2. Solution
      3. How It Works
    7. 3-7. Checking for Anagrams Without Sorting Characters
      1. Problem
      2. Solution
      3. How It Works
    8. 3-8. Creating a Rudimentary Programming Language Identifier and Automatic Syntax Highlighter
      1. Problem
      2. Solution
      3. How It Works
    9. 3-9. Creating a Word-Ladder Solver
      1. Problem
      2. Solution
      3. How It Works
    10. 3-10. Formatting on the Fly
      1. Problem
      2. Solution
      3. How It Works
    11. 3-11. Solving Eric Lippert’s Comma-Quibbling Problem
      1. Problem
      2. Solution
      3. How It Works
    12. 3-12. Generating Random Serials
      1. Problem
      2. Solution
      3. How It Works
    13. 3-13. Generating All Substrings of a Given String
      1. Problem
      2. Solution
      3. How It Works
    14. 3-14. Creating a Scrabble Cheater
      1. Problem
      2. Solution
      3. How It Works
    15. 3-15. Finding All the Subsequences of a Given String
      1. Problem
      2. Solution
      3. How It Works
    16. 3-16. Squeezing a Paragraph to Fill Tightly
      1. Problem
      2. Solution
      3. How It Works
    17. 3-17. Printing the Lines of a Song
      1. Problem
      2. Solution
      3. How It Works
    18. 3-18. Mining Abbreviations and Full Forms from News Articles
      1. Problem
      2. Solution
      3. How It Works
    19. Summary
  14. Chapter 4: Refactoring with LINQ
    1. 4-1. Replacing Loops by Using LINQ Operators
      1. A General Strategy to Transform a Loop to a LINQ Query
    2. 4-2. The Any Operator
      1. Problem
      2. Solution
      3. How It Works
    3. 4-3. The All Operator
      1. Problem
      2. Solution
      3. How It Works
    4. 4-4. The Take Operator
      1. Problem
      2. Solution
      3. How It Works
    5. 4-5. The Skip Operator
      1. Problem
      2. Solution
      3. How It Works
    6. 4-6. The TakeWhile Operator
      1. Problem
      2. Solution
      3. How It Works
    7. 4-7. The SkipWhile Operator
      1. Problem
      2. Solution
      3. How It Works
    8. 4-8. The Where Operator
      1. Problem
      2. Solution
      3. How It Works
    9. 4-9. The Zip Operator
      1. Problem
      2. Solution
      3. How It Works
    10. 4-10. OrderBy and OrderByDescending Operators
      1. Problem
      2. Solution
      3. How It Works
    11. 4-11. The Distinct Operator
      1. Problem
      2. Solution
      3. How It Works
    12. 4-12. The Union Operator
      1. Problem
      2. Solution
      3. How It Works
    13. 4-13. The Intersect Operator
      1. Problem
      2. Solution
      3. How It Works
    14. 4-14. The Except Operator
      1. Problem
      2. Solution
      3. How It Works
    15. 4-15. The Concat Operator
      1. Problem
      2. Solution
      3. How It Works
    16. 4-16. The SequenceEqual Operator
      1. Problem
      2. Solution
      3. How It Works
    17. 4-17. The Of Type Operator
      1. Problem
      2. Solution
      3. How It Works
    18. 4-18. The Cast Operator
      1. Problem
      2. Solution
      3. How It Works
    19. 4-19. The Aggregate Operator
      1. Problem
      2. Solution
      3. How It Works
    20. 4-20. Replacing Nested Loops
      1. The SelectMany Operator
      2. Removing Nested Loops by Using SelectMany
      3. Replacing If-Else Blocks Inside a Loop
    21. 4-21. Running Code in Parallel Using AsParallel( ) and AsOrdered( ) Operators
      1. Problem
      2. Solution
      3. How It Works
    22. Summary
  15. Chapter 5: Refactoring with MoreLINQ
    1. 5-1. Getting MoreLINQ
    2. 5-2. Using the Scan Operator
      1. Problem
      2. Solution
      3. How It Works
    3. 5-3. Using the Slice Operator
      1. Problem
      2. Solution
      3. How It Works
    4. 5-4. Using the Interleave Operator
      1. Problem
      2. Solution
      3. How It Works
    5. 5-5. Using the Windowed Operator
      1. Problem
      2. Solution
      3. How It Works
    6. 5-6. Using the Cartesian Operator
      1. Problem
      2. Solution
      3. How It Works
    7. 5-7. Using the Partition Operator
      1. Problem
      2. Solution
      3. How It Works
    8. 5-8. Using the Index Operator
      1. Problem
      2. Solution
      3. How It Works
    9. 5-9. Using the PairWise Operator
      1. Problem
      2. Solution
      3. How It Works
    10. 5-10. The ForEach Operator
      1. Problem
      2. Solution
      3. How It Works
    11. 5-11. Using the MinBy/MaxBy Operator
      1. Problem
      2. Solution
      3. How It Works
    12. Summary
  16. Chapter 6: Creating Domain-Specific Languages
    1. 6-1. Feel the Difference
    2. 6-2. Creating a Simple DSL for Mathematicians
      1. Problem
      2. Solution
      3. How It Works
    3. 6-3. Testing Armstrong by Using NUnit
      1. Problem
      2. Solution
      3. How It Works
    4. 6-4. Exposing Armstrong as an External DSL
      1. Problem
      2. Solution
      3. How It Works
    5. 6-5. Cloning Handy F# Functions by Using LINQ
      1. Problem
      2. Solution
      3. How It Works
    6. 6-6. Lazily Generating Items from a Recurrence Relation
      1. Problem
      2. Solution
      3. How It Works
    7. Summary
  17. Chapter 7: Static Code Analysis
    1. 7-1. Finding Verbose Type Names in the .NET 3.5 Framework
      1. Problem
      2. Solution
      3. How It Works
    2. 7-2. Finding the Number of Overloads for a Method
      1. Problem
      2. Solution
      3. How It Works
    3. 7-3. Finding the Size of a Namespace
      1. Problem
      2. Solution
      3. How It Works
    4. 7-4. Finding the Code-to-Comment (C# Style) Ratio
      1. Problem
      2. Solution
      3. How It Works
    5. 7-5. Finding the Size of Types
      1. Problem
      2. Solution
      3. How It Works
    6. 7-6. Generating Documentation Automatically
      1. Problem
      2. Solution
      3. How It Works
    7. 7-7. Finding Inheritance Relationships
      1. Problem
      2. Solution
      3. How It Works
    8. 7-8. Locating Complex Methods
      1. Problem
      2. Solution
      3. How It Works
    9. Summary
  18. Chapter 8: Exploratory Data Analysis
    1. 8-1. Analyzing the Titanic Survivors Dataset
      1. Problem
      2. Solution
      3. How It Works
      4. Problem
      5. Solution
      6. How It Works
    2. 8-2. Converting SurveyMonkey Results to CSV
      1. Problem
      2. Solution
      3. How It Works
    3. 8-3. Analyzing Trends in Baby Names
      1. Problem
      2. Solution
      3. How It Works
    4. 8-4. Analyzing Stock Values
      1. Problem
      2. Solution
      3. How It Works
    5. 8-5. Analyzing Git Logs
      1. Problem
      2. Solution
      3. How It Works
      4. Problem
      5. Solution
      6. How It Works
    6. 8-6. Analyzing Movie Ratings
      1. Problem
      2. Solution
      3. How It Works
    7. 8-7. Identifying Flowers by Using Machine Learning
      1. Problem
      2. Solution
      3. How It Works
    8. Summary
  19. Chapter 9: Interacting with the File System
    1. 9-1. Comparing Two CSV Files
      1. Problem
      2. Solution
      3. How It Works
    2. 9-2. Finding the Total File Size in a Directory
      1. Problem
      2. Solution
      3. How It Works
    3. 9-3. Cloning LINUX Head and Tail Commands
      1. Problem
      2. Solution
      3. How It Works
    4. 9-4. Locating Files with the Same Name (Possible Duplicates)
      1. Problem
      2. Solution
      3. How It Works
    5. 9-5. Finding Exact-Duplicate Files
      1. Problem
      2. Solution
      3. How It Works
    6. 9-6. Organizing Downloads Automatically
      1. Problem
      2. Solution
      3. How It Works
    7. 9-7. Finding Files Modified Last Week
      1. Problem
      2. Solution
      3. How It Works
    8. 9-8. Locating Dead Files (Files with Zero Bytes)
      1. Problem
      2. Solution
      3. How It Works
  20. Appendix A: Lean LINQ Tips
    1. Tip 1
      1. Explanation
    2. Tip 2
      1. Explanation
    3. Tip 3
      1. Explanation
    4. Tip 4
      1. Explanation
    5. Tip 5
      1. Explanation
    6. Tip 6
      1. Explanation
    7. Tip 7
      1. Explanation
    8. Tip 8
      1. Explanation
    9. Tip 9
      1. Explanation
    10. Tip 10
      1. Explanation
    11. Tip 11
      1. Explanation
    12. Tip 12
      1. Explanation
    13. Tip 13
      1. Explanation
    14. Tip 14
      1. Explanation
    15. Tip 15
      1. Explanation
    16. Tip 16
      1. Explanation
    17. Tip 17
      1. Explanation
  21. Appendix B: Taming Streaming Data with Rx.NET
    1. A Brief Explanation of the Interfaces
    2. Getting Rx.NET
    3. Using Rx.NET in LINQPad
    4. Creating Observables and Subscribing
      1. Range
      2. Repeat
      3. Never
      4. Interval
      5. Generate
      6. ToObservable
    5. Creating Observables from .NET Events
      1. Subscribe
    6. Combining Observable Collections
      1. Concat
      2. Merge
      3. Amb
      4. Zip
    7. Partitioning Observables
      1. Window
    8. Time-Tagging Observables
      1. Timestamp
      2. TimeInterval
    9. Rx.NET Showcase
      1. Creating a Signature Capture Screen
      2. Live File System Watcher
    10. Summary
  22. Index