Level Up Your Functional Programming Skills with LINQ

Cameron Presley
Cameron PresleySoftware Engineer at SentryOne
@pcameronpresley
Level Up on FP
Rebuilding LINQ
Cameron Presley
Cameron@TheSoftwareMentor.com
@pcameronpresley 2
Hello!
@pcameronpresley
What is LINQ?
Fundamentals
Implementing the Trinity
3
4
@pcameronpresley 5
@pcameronpresley 6
Which Delivery Teams
Have More
Than 7 Members?
@pcameronpresley 7
@pcameronpresley 8
@pcameronpresley
“Set of operations that works on data
independent of the source
In addition, these operations are type safe,
allowing the compiler to catch your
mistakes sooner
9
@pcameronpresley
Why LINQ?
10
@pcameronpresley
What Makes LINQ Work?
1. Func
2. Generics
3. Extension Methods
11
@pcameronpresley
Getting Functional with Funcs!
12
@pcameronpresley
Background
◦ Introduced in C# 3.0
◦ Type that when invoked returns a value
◦ Requires 0 or more parameters
13
@pcameronpresley
@pcameronpresley
Func<DeliveryTeam, bool>
Func<DeliveryTeam, string>
@pcameronpresley 16
@pcameronpresley 17
@pcameronpresley
Writing General Code
Generics
18
@pcameronpresley
Background
◦ Introduced in C# 2.0
◦ Allows for type parameters for various
constructs
◦ Great for when the type doesn’t matter
for implementation
19
@pcameronpresley 20
@pcameronpresley
@pcameronpresley 22
@pcameronpresley
When Generics Make Sense
When you’re writing the third structure in a
row…
Logic is the same, only the types are
different
23
@pcameronpresley 24
Extending Type Functionality
Extension Methods
@pcameronpresley
Background
◦ Introduced in C# 3.0
◦ Extends functionality to types without
having to recompile or creating a new
type
◦ Great for when working with types you
don’t have access to
25
@pcameronpresley 26
@pcameronpresley 27
You Could Have
Invented LINQ!
@pcameronpresley
“The most common extension methods
are the LINQ standard query operators
that add query functionality to the
existing System.Collections.IEnumerable
and
System.Collections.Generic.IEnumerable
<T> types.
28
MS Docs on Extension Methods
29
@pcameronpresley
Design Guidelines
◦ Extend the IEnumerable type
◦ Same signatures of LINQ
◦ Same properties as LINQ
30
@pcameronpresley
Changing Types with Map
31
@pcameronpresley
Background
Changes a collection of one type to
another by using a mapper function
Maintains the length of the collection
32
@pcameronpresley 33
Given a collection of DeliveryTeams,
we want to see the names, so we write the following
@pcameronpresley 34
@pcameronpresley 35
Given a collection of DeliveryTeams,
we want to see the TeamLeads, so we write the following
@pcameronpresley 36
@pcameronpresley 37
@pcameronpresley
@pcameronpresley 39
Given a collection of DeliveryTeams,
we want to know the number of team members on each team
@pcameronpresley 40
@pcameronpresley 41
@pcameronpresley 42
@pcameronpresley 43
Any reason we need to constraint this to the DeliveryTeam type?
@pcameronpresley 44
Select Imp from GitHub
@pcameronpresley 45
Do we need to limit to
List<TSource> and List<TResult>?
@pcameronpresley
“Use Map to Transform the
Collection Into The Data You
Need
46
@pcameronpresley
Keeping What’s Needed with Keep
47
@pcameronpresley
Background
Returns a subset of a collection based on a
predicate
Length is between 0 and original length
Doesn’t return items that weren’t in the
list
Maintains order
48
49
Which DeliveryTeams have more than 7 team members?
50
Which DeliveryTeams have Dana as a TeamLead?
51
52
@pcameronpresley 53
@pcameronpresley 54
Any reason why this would be
limited to DeliveryTeam?
55
@pcameronpresley 56
Where Implementation from GitHub
@pcameronpresley
“Use Keep to Keep Data That
You Want
57
@pcameronpresley
Going from many to one with
Reduce
58
@pcameronpresley
Background
Takes a collection, an initial value, and a
combiner method, returns a single value
59
@pcameronpresley 60
How many team members do we have in total?
@pcameronpresley 61
@pcameronpresley 62
@pcameronpresley 63
@pcameronpresley 64
@pcameronpresley 65
Any reason why this should only
work on DeliveryTeam?
@pcameronpresley 66
@pcameronpresley 67
Aggregate Imp from GitHub
@pcameronpresley
“Use Reduce to Transform a
Collection to a Single Value by
First Identifying the Initial
Value, Followed by Writing
the Combining Logic
68
@pcameronpresley
Reducing LINQ to Reduce
69
No, Seriously…
@pcameronpresley
Breaking Down The Problem
◦ Determine the Initial Value
◦ Determine how to combine the initial
value with the next element
70
@pcameronpresley 71
What’s the initial value?
What should we return if the source is empty?
Enumerable<TResult>.Empty()
@pcameronpresley
Setting Up Map via Reduce
72
1. Covert item from T to TResult
2. Append the converted item to values
@pcameronpresley
Converting from T to TResult
73
@pcameronpresley
Appending to values
74
@pcameronpresley
Redoing Keep as Reduce
75
@pcameronpresley 76
What’s the initial value?
What should we return if the source is empty?
Enumerable<TSource>.Empty()
@pcameronpresley
Setting Up Keep via Reduce
77
1. Check if the item meets the criteria
2. If the item meets, append to values
%%
@pcameronpresley
Checking if an item is valid
78
@pcameronpresley
Appending to values
79
@pcameronpresley
What Did We Cover?
What is LINQ?
Fundamentals (Func, Generics, Extension
Methods)
Implementing Map, Keep, Reduce
80
@pcameronpresley
LINQ isn’t magic
81
@pcameronpresley
Composition of Funcs,
Generics, Extension Methods
82
@pcameronpresley
Building bigger programs
from smaller programs
83
@pcameronpresley
Questions?
Cameron@TheSoftwareMentor.com
84
1 of 84

Recommended

【論文紹介】PGQ: Combining Policy Gradient And Q-learning by
【論文紹介】PGQ: Combining Policy Gradient And Q-learning【論文紹介】PGQ: Combining Policy Gradient And Q-learning
【論文紹介】PGQ: Combining Policy Gradient And Q-learningSotetsu KOYAMADA(小山田創哲)
6K views44 slides
Python Course | Python Programming | Python Tutorial | Python Training | Edureka by
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaEdureka!
4.1K views22 slides
CUDAメモ by
CUDAメモCUDAメモ
CUDAメモYuuki Takano
2.3K views20 slides
Python-Polymorphism.pptx by
Python-Polymorphism.pptxPython-Polymorphism.pptx
Python-Polymorphism.pptxKarudaiyar Ganapathy
234 views8 slides
Sour Pickles by
Sour PicklesSour Pickles
Sour PicklesSensePost
3.8K views97 slides
Establishing a SOLID Foundation by
Establishing a SOLID FoundationEstablishing a SOLID Foundation
Establishing a SOLID FoundationCameron Presley
357 views91 slides

More Related Content

Similar to Level Up Your Functional Programming Skills with LINQ

The Engineer's Playbook: Starting a New Role by
The Engineer's Playbook: Starting a New RoleThe Engineer's Playbook: Starting a New Role
The Engineer's Playbook: Starting a New RoleCameron Presley
73 views134 slides
Learning postgresql by
Learning postgresqlLearning postgresql
Learning postgresqlDAVID RAUDALES
294 views93 slides
Distributed System explained (with Java Microservices) by
Distributed System explained (with Java Microservices)Distributed System explained (with Java Microservices)
Distributed System explained (with Java Microservices)Mario Romano
296 views35 slides
Machine Learning Infrastructure by
Machine Learning InfrastructureMachine Learning Infrastructure
Machine Learning InfrastructureSigOpt
604 views14 slides
Deeplearning for industries | Data to Production by
Deeplearning for industries | Data to ProductionDeeplearning for industries | Data to Production
Deeplearning for industries | Data to ProductionRahul Kumar
31 views45 slides
Java On CRaC by
Java On CRaCJava On CRaC
Java On CRaCSimon Ritter
459 views35 slides

Similar to Level Up Your Functional Programming Skills with LINQ(20)

The Engineer's Playbook: Starting a New Role by Cameron Presley
The Engineer's Playbook: Starting a New RoleThe Engineer's Playbook: Starting a New Role
The Engineer's Playbook: Starting a New Role
Cameron Presley73 views
Distributed System explained (with Java Microservices) by Mario Romano
Distributed System explained (with Java Microservices)Distributed System explained (with Java Microservices)
Distributed System explained (with Java Microservices)
Mario Romano296 views
Machine Learning Infrastructure by SigOpt
Machine Learning InfrastructureMachine Learning Infrastructure
Machine Learning Infrastructure
SigOpt604 views
Deeplearning for industries | Data to Production by Rahul Kumar
Deeplearning for industries | Data to ProductionDeeplearning for industries | Data to Production
Deeplearning for industries | Data to Production
Rahul Kumar31 views
Back to Basics Webinar 3: Introduction to Replica Sets by MongoDB
Back to Basics Webinar 3: Introduction to Replica SetsBack to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica Sets
MongoDB2.2K views
Deep learning with kafka by Nitin Kumar
Deep learning with kafkaDeep learning with kafka
Deep learning with kafka
Nitin Kumar429 views
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino by Codemotion Tel Aviv
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG TorinoDistributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
Distributed System explained (with NodeJS) - Bruno Bossola - Codemotion Milan... by Codemotion
Distributed System explained (with NodeJS) - Bruno Bossola - Codemotion Milan...Distributed System explained (with NodeJS) - Bruno Bossola - Codemotion Milan...
Distributed System explained (with NodeJS) - Bruno Bossola - Codemotion Milan...
Codemotion3K views
ORACLE PL SQL FOR BEGINNERS by mohdoracle
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERS
mohdoracle18.6K views
FluentMigrator - Dayton .NET - July 2023 by Matthew Groves
FluentMigrator - Dayton .NET - July 2023FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023
Matthew Groves40 views
Computer 10 Quarter 3 Lesson .ppt by RedenOriola
Computer 10 Quarter 3 Lesson .pptComputer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .ppt
RedenOriola8 views
Automation for Anyone at Nutanix NEXT 2017 US by Chris Wahl
Automation for Anyone at Nutanix NEXT 2017 USAutomation for Anyone at Nutanix NEXT 2017 US
Automation for Anyone at Nutanix NEXT 2017 US
Chris Wahl477 views
From Mess To Masterpiece - JFokus 2017 by Sven Ruppert
From Mess To Masterpiece - JFokus 2017From Mess To Masterpiece - JFokus 2017
From Mess To Masterpiece - JFokus 2017
Sven Ruppert179 views
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016 by Alexander Lisachenko
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016 Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
2012 07 making disqus realtime@euro python by Adam Hitchcock
2012 07 making disqus realtime@euro python2012 07 making disqus realtime@euro python
2012 07 making disqus realtime@euro python
Adam Hitchcock489 views

More from Cameron Presley

Taking a Gamble with Functional Domain Modeling by
Taking a Gamble with Functional Domain ModelingTaking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain ModelingCameron Presley
152 views88 slides
Functional Programming Through Construction : First Principles by
Functional Programming Through Construction : First PrinciplesFunctional Programming Through Construction : First Principles
Functional Programming Through Construction : First PrinciplesCameron Presley
117 views86 slides
How Functional Programming Made Me a Better Developer by
How Functional Programming Made Me a Better DeveloperHow Functional Programming Made Me a Better Developer
How Functional Programming Made Me a Better DeveloperCameron Presley
454 views76 slides
How to Have Code Reviews That Developers Actually Want by
How to Have Code Reviews That Developers Actually WantHow to Have Code Reviews That Developers Actually Want
How to Have Code Reviews That Developers Actually WantCameron Presley
500 views59 slides
Making the Unstable Stable - An Intro To Testing by
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingCameron Presley
432 views68 slides
Indy Code - Taking a Gamble With F#: Implementing Blackjack by
Indy Code - Taking a Gamble With F#: Implementing BlackjackIndy Code - Taking a Gamble With F#: Implementing Blackjack
Indy Code - Taking a Gamble With F#: Implementing BlackjackCameron Presley
727 views109 slides

More from Cameron Presley(8)

Taking a Gamble with Functional Domain Modeling by Cameron Presley
Taking a Gamble with Functional Domain ModelingTaking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain Modeling
Cameron Presley152 views
Functional Programming Through Construction : First Principles by Cameron Presley
Functional Programming Through Construction : First PrinciplesFunctional Programming Through Construction : First Principles
Functional Programming Through Construction : First Principles
Cameron Presley117 views
How Functional Programming Made Me a Better Developer by Cameron Presley
How Functional Programming Made Me a Better DeveloperHow Functional Programming Made Me a Better Developer
How Functional Programming Made Me a Better Developer
Cameron Presley454 views
How to Have Code Reviews That Developers Actually Want by Cameron Presley
How to Have Code Reviews That Developers Actually WantHow to Have Code Reviews That Developers Actually Want
How to Have Code Reviews That Developers Actually Want
Cameron Presley500 views
Making the Unstable Stable - An Intro To Testing by Cameron Presley
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
Cameron Presley432 views
Indy Code - Taking a Gamble With F#: Implementing Blackjack by Cameron Presley
Indy Code - Taking a Gamble With F#: Implementing BlackjackIndy Code - Taking a Gamble With F#: Implementing Blackjack
Indy Code - Taking a Gamble With F#: Implementing Blackjack
Cameron Presley727 views
How Functional Programming Made Me A Better Developer by Cameron Presley
How Functional Programming Made Me A Better DeveloperHow Functional Programming Made Me A Better Developer
How Functional Programming Made Me A Better Developer
Cameron Presley328 views
Establishing a SOLID Foundation - An Intro to Software Design by Cameron Presley
Establishing a SOLID Foundation - An Intro to Software DesignEstablishing a SOLID Foundation - An Intro to Software Design
Establishing a SOLID Foundation - An Intro to Software Design
Cameron Presley201 views

Recently uploaded

Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Marc Müller
41 views83 slides
Keep by
KeepKeep
KeepGeniusee
77 views10 slides
Software evolution understanding: Automatic extraction of software identifier... by
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...Ra'Fat Al-Msie'deen
9 views33 slides
Quality Engineer: A Day in the Life by
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the LifeJohn Valentino
6 views18 slides
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...Deltares
14 views23 slides
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...sparkfabrik
7 views46 slides

Recently uploaded(20)

Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller41 views
Software evolution understanding: Automatic extraction of software identifier... by Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino6 views
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares14 views
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik7 views
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri860 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy14 views
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft... by Deltares
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
Deltares7 views
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols by Deltares
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - DolsDSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
Deltares9 views
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares10 views
Airline Booking Software by SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta6 views
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... by TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin96 views
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
Headless JS UG Presentation.pptx by Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor8 views

Level Up Your Functional Programming Skills with LINQ