Thinking in LINQ: Harnessing the Power of Functional Programming in .NET Applications

Thinking in LINQ: Harnessing the Power of Functional Programming in .NET Applications

Sudipta Mukherjee

Language: English

Pages: 272

ISBN: 143026845X

Format: PDF / Kindle (mobi) / ePub


LINQ represents a paradigm shift for developers used to an imperative/object oriented programming style, because LINQ draws on functional programming principles. Thinking in LINQ addresses the differences between these two by providing a set of succinct recipes arranged in several groups, including:

  • Basic and extended LINQ operators
  • Text processing
  • Loop refactoring
  • Monitoring code health
  • Reactive Extensions (Rx.NET)
  • Building domain-specific languages

Using the familiar "recipes" approach, Thinking in LINQ shows you how to approach building LINQ-based solutions, how such solutions are different from what you already know, and why they’re better. The recipes cover a wide range of real-world problems, from using LINQ to replace existing loops, to writing your own Swype-like keyboard entry routines, to finding duplicate files on your hard drive. The goal of these recipes is to get you "thinking in LINQ," so you can use the techniques in your own code to write more efficient and concise data-intensive applications.

 

 

 

 

 

 

 

 

 

 

 

 

given answer. Problem Write a program that generates answers for a Go Figure puzzle. 38 CHAPTER 2 N SERIES GENERATION Solution The program in Listing 2-24 solves the puzzle. Listing 2-24. Generating answers for a Go-Figure puzzle //Assume the answer we want to reach is "10" int answer = 10 ; //And we want to create 10 using 1, 2, 4 and 9 List set = new List() {1,2,4,9}; List> query = set.SelectMany ((s,i) => set.Where (se => se!=s) .Select (se => new

is on key 4, o and m are both on key 6, and e is on key 3. Thus the numeric key for the word home is 4663. Figure 3-3 represents the entire keypad. Each line shows the numeric key and the corresponding letters that can be entered by pressing that key. The Key column represents a key on the mobile phone’s keypad. The Value column represents all the characters a user can enter with that key. So the first line shows, for example, that by pressing the 2 key, users can enter an a, b, c, or of course

names1[i]; for (int i = 0, j = names1.Length; i < names2. Length; i++, j++) names[j] = names2[i]; string[] names1 = {"Sam","David","Erik","Daniel"}; string[] names2 = {"David","Erik","Samuel"}; string[] names = names1.Concat(names2). ToArray(); 4-16. The SequenceEqual Operator The SequenceEqual operator checks whether two sequences have the same element at each index, starting from the 0th index and maintaining the order. Problem Check whether two integer arrays are equal. Solution Use the

int[] distances = {23,41,11,34,45}; //The value that minimizes the given function f(x) = x - 10 //in this case distances. MinBy(a => a - 10).Dump(); //The minimum value of the values projected by the given formula distances. Min (a => a - 10).Dump(); int x = distances[0]; for(int i = 0;i

head and tail commands for Windows. Solution Listing 9-3 creates clones of the LINUX head and tail commands. Listing 9-3. Clone the Linux head and tail commands Func,int,IEnumerable> TakeLast = (list, count) => list.Skip(list.Count()-count); //Cloning head Func> Head = (fileName, lineCount)=> File.ReadAllLines(fileName).Take(lineCount); //Cloning tail Func> Tail = (fileName, lineCount)=>

Download sample

Download