-
Notifications
You must be signed in to change notification settings - Fork 1
Day 02 Generics Deferred enumerables and LINQ
Kobi Hari edited this page Sep 17, 2020
·
1 revision
Fun With Generics | Touching the hard points of .net Generics: Constraints, Covariance and Inference |
Intro to LINQ | Introduction to the lazy nature of .net LINQ |
- The purpose of Generics
- About Boxing and Unboxing
- Static members of Generic classes
- Generic Inference
- Generic Invariance, Covariance and Contravariance
- Generic Constraints
- We have created a value type for complex numbers:
Complex
- We have implemeneted
IEquatable<Complex>
to allow it to compare itself to otherComplex
instances - We discussed the
Equals
that we derive fromobject
and how to override it - We talked about how to overload the
==
operator- Always implement the
!=
operator too (the compiler enforces it) - Always override the
Equals
method fromobject
(the compiler warns if you do not) - Always override the
GetHashCode
method too (the compiler warns if you do not) - this is important to allow the object to be used as key inHashSets
- Always implement the
- We have created an iterator method using
yield return
- We have investigated the deferred execution nature of the enumerable and spotted 3 significant points in time:
- Calling the method itself - creates an instance of the IEnumerable
- Starting the
foreach
- creates an instance of the IEnumerator - Fetching the next item - runs the iterator method until the next
yield return
- We discussed the 2 ways to terminate an iterator
- By ending the method
- By calling
yield break
- We Defined an
IEnumerable
Operator as- A function that has predictable output per input
- That does not cause side effects
- That creates a new
IEnumerable
out of its source enumerable
- We created a
Map
operator that accepts a generic delegate and projects a new enumerable out of the source by applying the projection delegate on each item - We created a
TakeFirst
operator that accepts a (possibly) infinite stream and completes after the first few items - We discussed how infinite enumerables are even possible in the deferred execution paradigm
- Finally we talked about the basic most common LINQ operators:
-
Select
projection operator -
Where
filtering operator -
OrderBy
andThenBy
sorting operators -
Zip
combining operator
-
TBC next week