SlideShare une entreprise Scribd logo
1  sur  57
Esoteric LINQ
AND STRUCTURAL MADNESS
I Think Therefore I Am

    Chris Eargle
    Mad Scientist
    Telerik Evangelist
    C# MVP
    INETA Board of Directors
    Contacts
         kodefuguru.com
         kodefuguru@live.com
         callto://kodefuguru
“   It is not enough to have a
    good mind; the main
    thing is to use it well.
      RENE DESCARTES
                                 ”
Prepare();
var mind = blown;
This presentation is brought to you by Telerik.
Don’t worry. This is hardcore ideas and code, not a sales pitch.
Agenda

    Background Information
        Data Structures
        Design Patterns
        LINQ
    LINQ to Functions
    LINQ to Graphs
    LINQ to Specifications
Data Structures
A PRIMER
Common Data Structures

    Primitive Types
    Composite Types
    Abstract Types
Primitive Types

    These are struct types in C#
    Represents a single value
    Examples: bool, char, float, int
Composite Types

    In C#, everything else is a form of a composite type
    Typical examples
        Array
        Record
             Tuple
             Struct (not the C# struct)
             Plain Old Data Structure
        Union
        Tagged Union – Union that tracks current type
        Object – Data + Behavior
Abstract Types

    These are abstract composite types, structural implementations vary
    Examples
        Dictionary
        List
        Set
        Tree
        Graph
Graph

    Composed of nodes (or vertices) and edges



               Node

                         1          2        Edge



                         3          4            5
Digraph

    Apply a direction
    Removing direction is called the “underlying graph.”




                           1          2

                           3          4           5
Weighted Graph

    Edge contains value
    Useful for determining optimal routes between destinations



                                2.2
                           1          2
                        3.7             6.0
                                1.5           0.5
                           3          4             5
Multigraph

    More than one edge allowed between nodes




                        1         2

                        3         4         5
Hypergraph

    Edges can connect more than two nodes
    I view hyper-edges as categories




                          1             2

                          3             4    5
Tree

    A graph with parent-child relationships
    No node can be the child of more than one node



                      1          2

                                 3             4      5

                                               6
List

      A graph where each node is connected to 1 or 2 nodes
      Explicitly has an order




                     1           2   3          4             5
Set Comparisons

    List – Ordered, allows duplicates, single type
    Tuple – Ordered, allows duplicates, multiple types
    Set – Unordered, no duplicates, single type
Design Patterns
A PRIMER
“   A general reusable
    solution to a commonly
    occurring problem.
      WIKIPEDIA
                                                                      ”
Even if you do not know design patterns, you’ve probably used them.
Types of Design Patterns

    Creational Patterns
    Structural Patterns
    Behavioral Patterns
    Concurrency Patterns
    Architectural Patterns
Structural Patterns

    Difference with Data Structures
        Focus is to use structure to enable behavior
        There is potential overlap with abstract types
    Examples
        Adapter
        Composite
        Decorator
        Façade
        Flyweight
Behavioral Patterns

    Difference with Structural
        Behavior isn’t necessarily driven by the structure
    Examples
        Chain of Responsibility
        Command
        Iterator
        Observer
        Specification
        Visitor
Iterator

    an object that provides a standard way to examine all element of
     any collection.


    Has a uniform interface for traversing many data structure without
     exposing their implementations.


    Supports concurrent iteration and element removal.


    No need to know the internal structure of collection.
Iterator

            Aggregate          Client        Iterator
           <<interface>>                  <<interface>>
       + CreateIterator()               + First()
                                        + Next()
                                        + IsDone()
                                        + CurrentItem



           ConcreteAggregate             ConcreteIterator


       + CreateIterator()
Observer

    An object, called the subject, maintains a list of its dependents


    Dependents are known as observers


    Observers are notified when subject’s state changes
Observer

                                                          Subject
                        Observer
                                                   +observers
                                                   +Register(observer)
                 +Notify()                         +Unregister(observer)
                                                   +Notify()




    ConcreteObserverA              ConcreteObserverB


   +Notify()
Visitor

     Separates an algorithm from the structure on which it operates
Visitor

               Elementlike       Client        Visitable
              <<interface>>                 <<interface>>
            +Accept(visitable)            +Visit(element)




                  Element                        Visitor


          +Accept(visitable)
Specification

    Separates business rules from business objects
    Represents object-oriented predicates and predicate combinators
    Predicate – conditionals that can be passed
    The pattern uses “IsSpecifiedBy” to indicate whether the predicate is
     successful
Specification

    ISpecification               CompositeSpecification
    <<Interface>>
 +And()                          +And()
 +IsSatisfiedBy()                +IsSatisfiedBy()
 +Not()                          +Not()
 +Or()                           +Or()




           AndSpecification            OrSpecification           NotSpecification

       +left : ISpecification      +left : ISpecification
       +right : ISpecification     +right : ISpecification   +wrapped : ISpecification
LINQ
A PRIMER
Language Integrated Query

    Interrogate / manipulate data
    Type safe
    Misunderstood
Example Query

 from x in object1
 from y in object2
 select x + y;       What can you tell me
                           about
                          object1?
LINQ to Objects

    This is LINQ over the iterator pattern
    The iterator pattern in C# is implemented with IEnumerable
    Much more declarative than foreach loops
    Lazy Execution
LINQ to SQL/EF/Etc

    Uses visitor pattern
    Lambdas represent Expressions rather than functions
    Visitor translates expressions into another language
Reactive

    LINQ to observer pattern
    Items are pushed instead of pulled
    Great for asynchronous programming
    Is now open source
Materialization

 sequence.ToList();


                      This is typically
                          wrong.
Materialization

 sequence.Materialize();




 public static IEnumberable<T> Materialize(
   this IEnumerable<T> sequence)
 {
     return sequence.ToArray();
 }
Memoization

    Best of both worlds: Lazy Execution and Materialized results
    Cache results as collection is iterated
Code
LINQ to Functions
FUNCTIONAL COMBINATORS
What Does LINQ to Functions Mean

    Applying LINQ to new forms require reimagining the DSL
    In the case of functions, LINQ combines functions
    Each LINQ method is a functional combinator
“   a combinator is a function
    which builds program
    fragments from program
    fragments…
     JOHN HUGHES
                                 ”
Code
LINQ to Graphs
VERTICES AND EDGES
Select



         1       2    v` + 1   2       3
                     Select
             3                     4
SelectMany



            1       2      v` + w`   2       3   3       4
1   2   ,               SelectMany
                3                        4           5
SelectMany



       Expand   2       3   3       4

                    4           5
SelectMany



               2       3
        Fold
                   4       5
Where



        1       2   v` % 2 == 1

                    Where         1   3
            3
Code
LINQ to Specifications
PREDICATE COMBINATORS
Explanation

    Predicates are functions, but they combine differently than other
     functions
    Therefore, it makes more sense to wrap them so specific
     combinators can be applied
LINQ Weirdness

 from x in specification
 where x != 0
 select !x;
Code
Q&A

Contenu connexe

Tendances

Chapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaChapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaEduardo Bergavera
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshowilias ahmed
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
Sdtl manual
Sdtl manualSdtl manual
Sdtl manualqaz8989
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
Java căn bản - Chapter2
Java căn bản - Chapter2Java căn bản - Chapter2
Java căn bản - Chapter2Vince Vo
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Javabackdoor
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classesFajar Baskoro
 
Built in classes in java
Built in classes in javaBuilt in classes in java
Built in classes in javaMahmoud Ali
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywordsmanish kumar
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 

Tendances (19)

Chapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaChapter 2 - Getting Started with Java
Chapter 2 - Getting Started with Java
 
Java Generics
Java GenericsJava Generics
Java Generics
 
10slide
10slide10slide
10slide
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Sdtl manual
Sdtl manualSdtl manual
Sdtl manual
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
Java căn bản - Chapter2
Java căn bản - Chapter2Java căn bản - Chapter2
Java căn bản - Chapter2
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Java basic
Java basicJava basic
Java basic
 
Design Patterns: Back to Basics
Design Patterns: Back to BasicsDesign Patterns: Back to Basics
Design Patterns: Back to Basics
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
Built in classes in java
Built in classes in javaBuilt in classes in java
Built in classes in java
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywords
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 

Similaire à Esoteric LINQ and Structural Madness

OOP, API Design and MVP
OOP, API Design and MVPOOP, API Design and MVP
OOP, API Design and MVPHarshith Keni
 
Neal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary ArchitectureNeal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary ArchitectureThoughtworks
 
Changes and Bugs: Mining and Predicting Development Activities
Changes and Bugs: Mining and Predicting Development ActivitiesChanges and Bugs: Mining and Predicting Development Activities
Changes and Bugs: Mining and Predicting Development ActivitiesThomas Zimmermann
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternNitin Bhide
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of PatternsChris Eargle
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
Graph Databases in the Microsoft Ecosystem
Graph Databases in the Microsoft EcosystemGraph Databases in the Microsoft Ecosystem
Graph Databases in the Microsoft EcosystemMarco Parenzan
 
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptxStatic abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptxMarco Parenzan
 
The Ring programming language version 1.5.1 book - Part 5 of 180
The Ring programming language version 1.5.1 book - Part 5 of 180The Ring programming language version 1.5.1 book - Part 5 of 180
The Ring programming language version 1.5.1 book - Part 5 of 180Mahmoud Samir Fayed
 
Linked list basics
Linked list basicsLinked list basics
Linked list basicsRajesh Kumar
 
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)Spiros
 

Similaire à Esoteric LINQ and Structural Madness (20)

OOP, API Design and MVP
OOP, API Design and MVPOOP, API Design and MVP
OOP, API Design and MVP
 
Solid OOPS
Solid OOPSSolid OOPS
Solid OOPS
 
Neal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary ArchitectureNeal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary Architecture
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Changes and Bugs: Mining and Predicting Development Activities
Changes and Bugs: Mining and Predicting Development ActivitiesChanges and Bugs: Mining and Predicting Development Activities
Changes and Bugs: Mining and Predicting Development Activities
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of Patterns
 
Uml3
Uml3Uml3
Uml3
 
Hibernate
HibernateHibernate
Hibernate
 
Objective-C
Objective-CObjective-C
Objective-C
 
34. uml
34. uml34. uml
34. uml
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 
Graph Databases in the Microsoft Ecosystem
Graph Databases in the Microsoft EcosystemGraph Databases in the Microsoft Ecosystem
Graph Databases in the Microsoft Ecosystem
 
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptxStatic abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
 
The Ring programming language version 1.5.1 book - Part 5 of 180
The Ring programming language version 1.5.1 book - Part 5 of 180The Ring programming language version 1.5.1 book - Part 5 of 180
The Ring programming language version 1.5.1 book - Part 5 of 180
 
Chtp405
Chtp405Chtp405
Chtp405
 
Linked list basics
Linked list basicsLinked list basics
Linked list basics
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
Clojure
ClojureClojure
Clojure
 
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
 

Plus de Chris Eargle

Bring your existing .net skills to a cms
Bring your existing .net skills to a cmsBring your existing .net skills to a cms
Bring your existing .net skills to a cmsChris Eargle
 
Hidden Gems of the Sitefinity API Webinar
Hidden Gems of the Sitefinity API WebinarHidden Gems of the Sitefinity API Webinar
Hidden Gems of the Sitefinity API WebinarChris Eargle
 
Amp Up Your Visual Studio Productivity
Amp Up Your Visual Studio ProductivityAmp Up Your Visual Studio Productivity
Amp Up Your Visual Studio ProductivityChris Eargle
 
Easier with visual studio productivity tools
Easier with visual studio productivity toolsEasier with visual studio productivity tools
Easier with visual studio productivity toolsChris Eargle
 
One Engine Two Tools
One Engine Two ToolsOne Engine Two Tools
One Engine Two ToolsChris Eargle
 
2012 Q1 Tools for Better Code
2012 Q1 Tools for Better Code2012 Q1 Tools for Better Code
2012 Q1 Tools for Better CodeChris Eargle
 
Deep Dive: MVC Controller Architecture
Deep Dive: MVC Controller ArchitectureDeep Dive: MVC Controller Architecture
Deep Dive: MVC Controller ArchitectureChris Eargle
 
Building a multi touch enabled windows 7 point of sale system
Building a multi touch enabled windows 7 point of sale systemBuilding a multi touch enabled windows 7 point of sale system
Building a multi touch enabled windows 7 point of sale systemChris Eargle
 
Monadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query ExpressionsMonadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query ExpressionsChris Eargle
 

Plus de Chris Eargle (10)

Bring your existing .net skills to a cms
Bring your existing .net skills to a cmsBring your existing .net skills to a cms
Bring your existing .net skills to a cms
 
Hidden Gems of the Sitefinity API Webinar
Hidden Gems of the Sitefinity API WebinarHidden Gems of the Sitefinity API Webinar
Hidden Gems of the Sitefinity API Webinar
 
Amp Up Your Visual Studio Productivity
Amp Up Your Visual Studio ProductivityAmp Up Your Visual Studio Productivity
Amp Up Your Visual Studio Productivity
 
Easier with visual studio productivity tools
Easier with visual studio productivity toolsEasier with visual studio productivity tools
Easier with visual studio productivity tools
 
One Engine Two Tools
One Engine Two ToolsOne Engine Two Tools
One Engine Two Tools
 
2012 Q1 Tools for Better Code
2012 Q1 Tools for Better Code2012 Q1 Tools for Better Code
2012 Q1 Tools for Better Code
 
Deep Dive: MVC Controller Architecture
Deep Dive: MVC Controller ArchitectureDeep Dive: MVC Controller Architecture
Deep Dive: MVC Controller Architecture
 
Building a multi touch enabled windows 7 point of sale system
Building a multi touch enabled windows 7 point of sale systemBuilding a multi touch enabled windows 7 point of sale system
Building a multi touch enabled windows 7 point of sale system
 
Monadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query ExpressionsMonadic Comprehensions and Functional Composition with Query Expressions
Monadic Comprehensions and Functional Composition with Query Expressions
 
C# Ninjitsu
C# NinjitsuC# Ninjitsu
C# Ninjitsu
 

Esoteric LINQ and Structural Madness

  • 2. I Think Therefore I Am  Chris Eargle  Mad Scientist  Telerik Evangelist  C# MVP  INETA Board of Directors  Contacts  kodefuguru.com  kodefuguru@live.com  callto://kodefuguru
  • 3. It is not enough to have a good mind; the main thing is to use it well. RENE DESCARTES ” Prepare(); var mind = blown;
  • 4. This presentation is brought to you by Telerik. Don’t worry. This is hardcore ideas and code, not a sales pitch.
  • 5. Agenda  Background Information  Data Structures  Design Patterns  LINQ  LINQ to Functions  LINQ to Graphs  LINQ to Specifications
  • 7. Common Data Structures  Primitive Types  Composite Types  Abstract Types
  • 8. Primitive Types  These are struct types in C#  Represents a single value  Examples: bool, char, float, int
  • 9. Composite Types  In C#, everything else is a form of a composite type  Typical examples  Array  Record  Tuple  Struct (not the C# struct)  Plain Old Data Structure  Union  Tagged Union – Union that tracks current type  Object – Data + Behavior
  • 10. Abstract Types  These are abstract composite types, structural implementations vary  Examples  Dictionary  List  Set  Tree  Graph
  • 11. Graph  Composed of nodes (or vertices) and edges Node 1 2 Edge 3 4 5
  • 12. Digraph  Apply a direction  Removing direction is called the “underlying graph.” 1 2 3 4 5
  • 13. Weighted Graph  Edge contains value  Useful for determining optimal routes between destinations 2.2 1 2 3.7 6.0 1.5 0.5 3 4 5
  • 14. Multigraph  More than one edge allowed between nodes 1 2 3 4 5
  • 15. Hypergraph  Edges can connect more than two nodes  I view hyper-edges as categories 1 2 3 4 5
  • 16. Tree  A graph with parent-child relationships  No node can be the child of more than one node 1 2 3 4 5 6
  • 17. List  A graph where each node is connected to 1 or 2 nodes  Explicitly has an order 1 2 3 4 5
  • 18. Set Comparisons  List – Ordered, allows duplicates, single type  Tuple – Ordered, allows duplicates, multiple types  Set – Unordered, no duplicates, single type
  • 20. A general reusable solution to a commonly occurring problem. WIKIPEDIA ” Even if you do not know design patterns, you’ve probably used them.
  • 21. Types of Design Patterns  Creational Patterns  Structural Patterns  Behavioral Patterns  Concurrency Patterns  Architectural Patterns
  • 22. Structural Patterns  Difference with Data Structures  Focus is to use structure to enable behavior  There is potential overlap with abstract types  Examples  Adapter  Composite  Decorator  Façade  Flyweight
  • 23. Behavioral Patterns  Difference with Structural  Behavior isn’t necessarily driven by the structure  Examples  Chain of Responsibility  Command  Iterator  Observer  Specification  Visitor
  • 24. Iterator  an object that provides a standard way to examine all element of any collection.  Has a uniform interface for traversing many data structure without exposing their implementations.  Supports concurrent iteration and element removal.  No need to know the internal structure of collection.
  • 25. Iterator Aggregate Client Iterator <<interface>> <<interface>> + CreateIterator() + First() + Next() + IsDone() + CurrentItem ConcreteAggregate ConcreteIterator + CreateIterator()
  • 26. Observer  An object, called the subject, maintains a list of its dependents  Dependents are known as observers  Observers are notified when subject’s state changes
  • 27. Observer Subject Observer +observers +Register(observer) +Notify() +Unregister(observer) +Notify() ConcreteObserverA ConcreteObserverB +Notify()
  • 28. Visitor  Separates an algorithm from the structure on which it operates
  • 29. Visitor Elementlike Client Visitable <<interface>> <<interface>> +Accept(visitable) +Visit(element) Element Visitor +Accept(visitable)
  • 30. Specification  Separates business rules from business objects  Represents object-oriented predicates and predicate combinators  Predicate – conditionals that can be passed  The pattern uses “IsSpecifiedBy” to indicate whether the predicate is successful
  • 31. Specification ISpecification CompositeSpecification <<Interface>> +And() +And() +IsSatisfiedBy() +IsSatisfiedBy() +Not() +Not() +Or() +Or() AndSpecification OrSpecification NotSpecification +left : ISpecification +left : ISpecification +right : ISpecification +right : ISpecification +wrapped : ISpecification
  • 33. Language Integrated Query  Interrogate / manipulate data  Type safe  Misunderstood
  • 34. Example Query from x in object1 from y in object2 select x + y; What can you tell me about object1?
  • 35. LINQ to Objects  This is LINQ over the iterator pattern  The iterator pattern in C# is implemented with IEnumerable  Much more declarative than foreach loops  Lazy Execution
  • 36. LINQ to SQL/EF/Etc  Uses visitor pattern  Lambdas represent Expressions rather than functions  Visitor translates expressions into another language
  • 37. Reactive  LINQ to observer pattern  Items are pushed instead of pulled  Great for asynchronous programming  Is now open source
  • 38. Materialization sequence.ToList(); This is typically wrong.
  • 39. Materialization sequence.Materialize(); public static IEnumberable<T> Materialize( this IEnumerable<T> sequence) { return sequence.ToArray(); }
  • 40. Memoization  Best of both worlds: Lazy Execution and Materialized results  Cache results as collection is iterated
  • 41. Code
  • 43. What Does LINQ to Functions Mean  Applying LINQ to new forms require reimagining the DSL  In the case of functions, LINQ combines functions  Each LINQ method is a functional combinator
  • 44. a combinator is a function which builds program fragments from program fragments… JOHN HUGHES ”
  • 45. Code
  • 47. Select 1 2 v` + 1 2 3 Select 3 4
  • 48. SelectMany 1 2 v` + w` 2 3 3 4 1 2 , SelectMany 3 4 5
  • 49. SelectMany Expand 2 3 3 4 4 5
  • 50. SelectMany 2 3 Fold 4 5
  • 51. Where 1 2 v` % 2 == 1 Where 1 3 3
  • 52. Code
  • 54. Explanation  Predicates are functions, but they combine differently than other functions  Therefore, it makes more sense to wrap them so specific combinators can be applied
  • 55. LINQ Weirdness from x in specification where x != 0 select !x;
  • 56. Code
  • 57. Q&A