SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
Level Up Your Functional Programming Skills with LINQ
In this presentation, Cameron Presley shows you how to implement basic LINQ Operations leveraging Funcs, Generics, and Extension Methods. Once fundamentals are in place, Cameron starts building the various LINQ methods
In this presentation, Cameron Presley shows you how to implement basic LINQ Operations leveraging Funcs, Generics, and Extension Methods. Once fundamentals are in place, Cameron starts building the various LINQ methods
9.
@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
18.
@pcameronpresley
Writing General Code
Generics
18
19.
@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
23.
@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
24.
@pcameronpresley 24
Extending Type Functionality
Extension Methods
25.
@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
27.
@pcameronpresley 27
You Could Have
Invented LINQ!
28.
@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
45.
@pcameronpresley 45
Do we need to limit to
List<TSource> and List<TResult>?
46.
@pcameronpresley
“Use Map to Transform the
Collection Into The Data You
Need
46
47.
@pcameronpresley
Keeping What’s Needed with Keep
47
48.
@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.
49
Which DeliveryTeams have more than 7 team members?
50.
50
Which DeliveryTeams have Dana as a TeamLead?
68.
@pcameronpresley
“Use Reduce to Transform a
Collection to a Single Value by
First Identifying the Initial
Value, Followed by Writing
the Combining Logic
68
69.
@pcameronpresley
Reducing LINQ to Reduce
69
No, Seriously…
70.
@pcameronpresley
Breaking Down The Problem
◦ Determine the Initial Value
◦ Determine how to combine the initial
value with the next element
70
71.
@pcameronpresley 71
What’s the initial value?
What should we return if the source is empty?
Enumerable<TResult>.Empty()
72.
@pcameronpresley
Setting Up Map via Reduce
72
1. Covert item from T to TResult
2. Append the converted item to values
73.
@pcameronpresley
Converting from T to TResult
73