SlideShare une entreprise Scribd logo
1  sur  45
Chuck Durfee, 3 October 2012
BIG
DATA
Enumerable.Select(
  Enumerable.OrderBy(
    Enumerable.Where(names, s => s.Length == 5),
    s => s
  ),
  s => s.ToUpper()
);

                         versus
names.Where(s => s.Length == 5)
    .OrderBy(s => s)
    .Select(s => s.ToUpper())
, my dear Watson
1.0
delegate bool FilterMethod(string s);

private bool IsFiveLetterName(string s) {
  return s.Length == 5;
}

public DotNet10Land()
{
  FilterMethod filter = IsFiveLetterName;
}
2.0
delegate bool FilterMethod(string s);

public DotNet20Land()
{
  FilterMethod filter =
    delegate(string s) {
       return s.Length == 5;
    };
}
C# 3 = .NET 3.5
delegate bool FilterMethod(string s);

public DotNet35Land()
{
  string chuck = "chuck";
  FilterMethod filter =
    delegate(string s) {
      return s != chuck && s.Length == 5;
    };
}
Func
// delegate bool FilterMethod(string s);

public DotNet35Land()
{
  Func<string, bool> filter =
    delegate(string s) {
       return s.Length == 5;
    };
}
Func<string, bool>
Func<string, int, DateTime>
Func<List<string>, int, bool>


but not
Func<string, System.Void>
and… Action
// delegate void ActionMethod(string s);

public DotNet35Land()
{
  Action<string> action = delegate(string s) {
     if (s.Length != 5)
       throw new ArgumentException("Length != 5");
  };
}
LAMBDA EXPRESSIONS
Func<string, bool> filter =
     delegate(string s)     {return s.Length == 5;};

var filter = (string s) => {return s.Length == 5;};

var filter = (string s) => s.Length == 5;

var filter = (s)        => s.Length == 5;

var filter =   s        => s.Length == 5;
by Alonzo Church, 1930’s
string[] names = { "Tom", "Dick",
  "Harry" };

names.Select((s, i) =>
  (i + 1) + "=" + s);




 1=Tom
 2=Dick
 3=Harry
int[] numbers = { 3, 5, 7 };
string[] words = { "three", "five",
  "seven", "ignored" };

IEnumerable<string> zip =             3=three
  numbers.Zip(words,                  5=five
    (n, w) => n + "=" + w);           7=seven
IEnumerable<Order> spanishOrders =
customers
  .Where(c => c.Country == "Spain")
  .SelectMany(c => c.Orders);
var slowQuery =
from c in customers
from p in purchases where c.ID == p.CustomerID
select c.Name + " bought a " + p.Description;

var fastQuery =
from c in customers
join p in purchases on c.ID equals p.CustomerID
select c.Name + " bought a " + p.Description;
var easyToRead =
  from c in customers
  join p in purchases on c.ID equals p.CustomerID
  select c.Name + " bought a " + p.Description;

var harderToRead = customers.Join (
   purchases,
   c => (int?)(c.ID),
   p => p.CustomerID,
   (c, p) => ((c.Name + " bought a ") +
     p.Description)
);
public static class EnumerableExtensions
{
  public static string ToCsv<T>(
    this IEnumerable<T> sequence)
  {
    const string delimiter = ", ";
    return sequence.Aggregate(
       new StringBuilder(),
      (sb, s) => sb.Append(s + delimiter),
       sb => sb.ToString()
               .TrimEnd(delimiter.ToArray()));
  }
}

       new[] { 1, 2, 3, 5, 8, 13, 20 } => 1, 2, 3, 5, 8, 13, 20
Chuck Durfee
http://neontapir.com

Contenu connexe

Tendances

การเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐานการเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
minkminkk
 
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐานการเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
minkminkk
 
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐานการเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
minkminkk
 

Tendances (20)

Expression trees in C#
Expression trees in C#Expression trees in C#
Expression trees in C#
 
Writeable CTEs: The Next Big Thing
Writeable CTEs: The Next Big ThingWriteable CTEs: The Next Big Thing
Writeable CTEs: The Next Big Thing
 
c programming
c programmingc programming
c programming
 
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐานการเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
 
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐานการเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
 
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐานการเขียนคำสั่งควบคุมขั้นพื้นฐาน
การเขียนคำสั่งควบคุมขั้นพื้นฐาน
 
Disassembling Go
Disassembling GoDisassembling Go
Disassembling Go
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
 
Postgresql 9.3 overview
Postgresql 9.3 overviewPostgresql 9.3 overview
Postgresql 9.3 overview
 
c programming
c programmingc programming
c programming
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
The Ring programming language version 1.5.3 book - Part 20 of 184
The Ring programming language version 1.5.3 book - Part 20 of 184The Ring programming language version 1.5.3 book - Part 20 of 184
The Ring programming language version 1.5.3 book - Part 20 of 184
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - Function
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
 
F# intro
F# introF# intro
F# intro
 
Intersection Study - Algorithm(Search)
Intersection Study - Algorithm(Search)Intersection Study - Algorithm(Search)
Intersection Study - Algorithm(Search)
 
Ass2 1 (2)
Ass2 1 (2)Ass2 1 (2)
Ass2 1 (2)
 

En vedette (8)

Drupalcamp israel 2012
Drupalcamp israel 2012Drupalcamp israel 2012
Drupalcamp israel 2012
 
Lecture 6 & 7
Lecture 6 & 7Lecture 6 & 7
Lecture 6 & 7
 
Billie holiday
Billie holidayBillie holiday
Billie holiday
 
L&amp;D Strategy V2
L&amp;D Strategy V2L&amp;D Strategy V2
L&amp;D Strategy V2
 
2013 budget powerpoint 101512v3
2013 budget powerpoint 101512v32013 budget powerpoint 101512v3
2013 budget powerpoint 101512v3
 
PRaktiki_Newsletter_15.10.2012
PRaktiki_Newsletter_15.10.2012PRaktiki_Newsletter_15.10.2012
PRaktiki_Newsletter_15.10.2012
 
Ar fixed a4_0107
Ar fixed a4_0107Ar fixed a4_0107
Ar fixed a4_0107
 
Yarp1213
Yarp1213Yarp1213
Yarp1213
 

Similaire à Linq - an overview

Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
aleks-f
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 

Similaire à Linq - an overview (20)

Tuga it 2016 - What's New In C# 6
Tuga it 2016 - What's New In C# 6Tuga it 2016 - What's New In C# 6
Tuga it 2016 - What's New In C# 6
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Functional programming in java
Functional programming in javaFunctional programming in java
Functional programming in java
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
Java Puzzlers
Java PuzzlersJava Puzzlers
Java Puzzlers
 
Java 5 New Feature
Java 5 New FeatureJava 5 New Feature
Java 5 New Feature
 
What's new in C# 6 - NetPonto Porto 20160116
What's new in C# 6  - NetPonto Porto 20160116What's new in C# 6  - NetPonto Porto 20160116
What's new in C# 6 - NetPonto Porto 20160116
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Generics and Lambdas cocktail explained - Montreal JUG
Generics and Lambdas cocktail explained  - Montreal JUGGenerics and Lambdas cocktail explained  - Montreal JUG
Generics and Lambdas cocktail explained - Montreal JUG
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developers
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 
Java 8, lambdas, generics: How to survive? - NYC Java Meetup Group
Java 8, lambdas, generics: How to survive? - NYC Java Meetup GroupJava 8, lambdas, generics: How to survive? - NYC Java Meetup Group
Java 8, lambdas, generics: How to survive? - NYC Java Meetup Group
 
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
 
DevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a DatastoreDevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a Datastore
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Operators
OperatorsOperators
Operators
 
The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212
 

Dernier

Dernier (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Linq - an overview

  • 1. Chuck Durfee, 3 October 2012
  • 2.
  • 3.
  • 5.
  • 6.
  • 7.
  • 8. Enumerable.Select( Enumerable.OrderBy( Enumerable.Where(names, s => s.Length == 5), s => s ), s => s.ToUpper() ); versus names.Where(s => s.Length == 5) .OrderBy(s => s) .Select(s => s.ToUpper())
  • 9.
  • 10. , my dear Watson
  • 11.
  • 12. 1.0 delegate bool FilterMethod(string s); private bool IsFiveLetterName(string s) { return s.Length == 5; } public DotNet10Land() { FilterMethod filter = IsFiveLetterName; }
  • 13. 2.0 delegate bool FilterMethod(string s); public DotNet20Land() { FilterMethod filter = delegate(string s) { return s.Length == 5; }; }
  • 14. C# 3 = .NET 3.5 delegate bool FilterMethod(string s); public DotNet35Land() { string chuck = "chuck"; FilterMethod filter = delegate(string s) { return s != chuck && s.Length == 5; }; }
  • 15.
  • 16. Func // delegate bool FilterMethod(string s); public DotNet35Land() { Func<string, bool> filter = delegate(string s) { return s.Length == 5; }; }
  • 17. Func<string, bool> Func<string, int, DateTime> Func<List<string>, int, bool> but not Func<string, System.Void>
  • 18. and… Action // delegate void ActionMethod(string s); public DotNet35Land() { Action<string> action = delegate(string s) { if (s.Length != 5) throw new ArgumentException("Length != 5"); }; }
  • 19. LAMBDA EXPRESSIONS Func<string, bool> filter = delegate(string s) {return s.Length == 5;}; var filter = (string s) => {return s.Length == 5;}; var filter = (string s) => s.Length == 5; var filter = (s) => s.Length == 5; var filter = s => s.Length == 5;
  • 20. by Alonzo Church, 1930’s
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32. string[] names = { "Tom", "Dick", "Harry" }; names.Select((s, i) => (i + 1) + "=" + s); 1=Tom 2=Dick 3=Harry
  • 33.
  • 34. int[] numbers = { 3, 5, 7 }; string[] words = { "three", "five", "seven", "ignored" }; IEnumerable<string> zip = 3=three numbers.Zip(words, 5=five (n, w) => n + "=" + w); 7=seven
  • 35.
  • 36. IEnumerable<Order> spanishOrders = customers .Where(c => c.Country == "Spain") .SelectMany(c => c.Orders);
  • 37.
  • 38. var slowQuery = from c in customers from p in purchases where c.ID == p.CustomerID select c.Name + " bought a " + p.Description; var fastQuery = from c in customers join p in purchases on c.ID equals p.CustomerID select c.Name + " bought a " + p.Description;
  • 39.
  • 40. var easyToRead = from c in customers join p in purchases on c.ID equals p.CustomerID select c.Name + " bought a " + p.Description; var harderToRead = customers.Join ( purchases, c => (int?)(c.ID), p => p.CustomerID, (c, p) => ((c.Name + " bought a ") + p.Description) );
  • 41.
  • 42.
  • 43. public static class EnumerableExtensions { public static string ToCsv<T>( this IEnumerable<T> sequence) { const string delimiter = ", "; return sequence.Aggregate( new StringBuilder(), (sb, s) => sb.Append(s + delimiter), sb => sb.ToString() .TrimEnd(delimiter.ToArray())); } } new[] { 1, 2, 3, 5, 8, 13, 20 } => 1, 2, 3, 5, 8, 13, 20
  • 44.

Notes de l'éditeur

  1. C# 2 introduced generics, at that point, C# is feature complete for OO features
  2. Next challenge to tackle after OO features is Big Data, how to reduce complexity of integrating information
  3. Provide translation between database constructs and objects
  4. Easy way to query data sourceExtension methods, query comprehension syntaxWay to return arbitrary resultsAnonymous types,var keywordWay to pass input dataClosures, collection and object initializers
  5. http://www.paintingsoncanvas.net/print-111552-4043120/stone-age-man-making-weapon-giclee-print/
  6. http://www.travelwalls.net/wallpapers/2012/08/Walt-Disney-Concert-Hall-Modern-City-Los-Angeles-California-United-States-300x420.jpg
  7. http://www.efunda.com/math/bessel/images/BesselJPlot.gif
  8. http://portcityfilmfestival.com/clap-board.jpg
  9. http://watermarked.cutcaster.com/cutcaster-photo-100783484-Lambda-symbol-in-glass-3d.jpg
  10. http://cdn.abovethelaw.com/uploads/2012/02/thank-you.jpg