SlideShare a Scribd company logo
C# - Raise the bar with functional & immutable constructs (Dutch)
C#
Raise the bar with Functional & Immutable
constructs
O, Kan dat ook?
Today
• Func is cool
• Tuple is your friend
• Immutable is a life saver
• Practice makes perfect
• Action!
Action
public delegate void Action<in T1, in T2>(T1
arg1, T2 arg2);
Func
public delegate TResult
Func<in T1, in T2, out TResult>(T1 arg1, T2
arg2);
Tuple
public class Tuple<T1, T2> :
IStructuralEquatable, IStructuralComparable,
IComparable, Ituple
Tuple: Equality
Functions
• Data in – Data out
• Func in – Data out
• Data in – Func out
• Func in – Func out
Functions: Data in – Data out
x => 2 * x
Functions: Func in – Data out
• LINQ: Where + more
• Example: Object initialize
• GitHub:
https://github.com/NForza/Functional/tree/ma
ster/Samples/ObjectInitialization
• Example: Aggregate
• GitHub:
https://github.com/NForza/Functional/tree/ma
ster/Samples/Aggregate
Functions: Data in – Func out
x => y => x + y
Functions: Func in – Func out
• Example: Partial application
• Example: Memoize
Partial Application
var f = (x, y) => x + y;
var p = x => y => f(x, y);
Partial Application
• GitHub:
https://github.com/NForza/Functional/tree/
master/Samples/Partial
Memoization
• Pure functions
• Long running operations
Memoization Cache
Now:
• Unlimited size, unlimited time
Ideas:
• Limited size, unlimited time
• Unlimited size, limited time
• Don’t use the cache unless real function
takes > 1 sec.
Memoization
• GitHub:
https://github.com/NForza/Memoization
• NuGet:
https://www.nuget.org/packages/Memoizat
ion
Abstractions
• 1 or n
• for
• Is Index needed?
• Is List/IList the correct abstraction (do we need
to change the list?)
• foreach
• What & How are together
• I hear functional abstraction
• Return: IEnumerable, IDictionary, IGroup
Abstraction Examples
• Interactive Extensions
• NuGet:
https://www.nuget.org/packages/Ix-Main/
• NForza Extensions
• GitHub:
https://github.com/NForza/Functional
• NuGet: Soon!
• Weighted Average
• GitHub:
https://github.com/NForza/Functional/blob/master
/Sources/NForza.Functional/EnumerableExtensions.
cs#L563-601
Miscellaneous Examples
• Defer (make Lazy)
• GitHub:
https://github.com/NForza/Functional/tree/ma
ster/Samples/Defer
• Bindings
• GitHub:
https://github.com/rickbeerendonk/Binding
• NuGet:
https://www.nuget.org/packages/Beerendonk.B
inding
Immutable: Why?
• Easier reasoning
• Equality Has Meaning
(not in .NET’s immutable colleactions)
• Sharing = Easy, no defensive copying
required!
No ToArray() / ToList()
• Concurrent Programming: No locks!
Immutable?
• Int
• String
• Tuple
• IEnumerable
• IReadOnlyCollection/List/Dictionary
• IList
Immutable Collections
• ImmutableList<T>
• ImmutableDictionary<TKey, TValue>
• ImmutableSortedDictionary<TKey, TValue>
• ImmutableHashSet<T>
• ImmutableSortedSet<T>
• ImmutableStack<T>
• ImmutableQueue<T>
Immutable Collections
• Demo:
https://github.com/rickbeerendonk/Immuta
bleDemo
• NuGet:
https://msdn.microsoft.com/en-
us/library/dn769092(v=vs.110).aspx
Immutable Coll.: Performance
Mutable
(amortized)
Mutable
(worst case)
Immutable
Stack.Push O(1) O(n) O(1)
Queue.Enqueue
e
O(1) O(n) O(1)
List.Add O(1) O(n) O(log n)
HashSet.Add O(1) O(n) O(log n)
SortedSet.Add O(log n) O(n) O(log n)
Dictionary.Add O(1) O(n) O(log n)
SortedDictionar
y.Add
O(log n) O(n log n) O(log n)
Immutable Coll.: Memory
• Worse: Per Item
• Better: No reserved space
• Better: Immediate shrink after delete
Why?
• Less code
• Reusable
• More fun!
Rick Beerendonk
rick@nforza.nl
twitter.com/rickbeerendonk
Simple. Clear. Software.

More Related Content

PDF
Data analytics in the cloud with Jupyter notebooks.
KEY
20120524 english lt2_pythontoolsfortesting
PDF
Parallel Programming in Python: Speeding up your analysis
PDF
IPython: A Modern Vision of Interactive Computing (PyData SV 2013)
PPTX
Jonathan Coveney: Why Pig?
PDF
Luigi future
PDF
Pharo Status Fosdem 2015
PDF
Jupyter Kernel: How to Speak in Another Language
Data analytics in the cloud with Jupyter notebooks.
20120524 english lt2_pythontoolsfortesting
Parallel Programming in Python: Speeding up your analysis
IPython: A Modern Vision of Interactive Computing (PyData SV 2013)
Jonathan Coveney: Why Pig?
Luigi future
Pharo Status Fosdem 2015
Jupyter Kernel: How to Speak in Another Language

What's hot (19)

PDF
Pharo Status ESUG 2014
PDF
GPU Computing for Data Science
PDF
Introduction to IPython & Jupyter Notebooks
PDF
Asynchronous Python A Gentle Introduction
PDF
Jupyter, A Platform for Data Science at Scale
PDF
Pytorch Ecosystem Day: The 珞 Ecosystem
PDF
PyTorch - an ecosystem for deep learning with Soumith Chintala (Facebook AI)
PDF
Zeppelin, TensorFlow, Deep Learning 맛보기
PDF
Puppet Camp Dallas 2014: How Puppet Ops Rolls
PDF
Real Time Graph Computations in Storm, Neo4J, Python - PyCon India 2013
PDF
Realtime processing with storm presentation
PDF
PharoDAYS 2015: Pharo Status - by Markus Denker
PDF
Pharo4: Plans and Dreams
PDF
SciPy 2019: How to Accelerate an Existing Codebase with Numba
PDF
Protocol libraries the right way
PDF
Creating Art with a Raspberry Pi - Stephanie Nemeth - Codemotion Amsterdam 2017
KEY
Numba lightning
PDF
Scale up and Scale Out Anaconda and PyData
Pharo Status ESUG 2014
GPU Computing for Data Science
Introduction to IPython & Jupyter Notebooks
Asynchronous Python A Gentle Introduction
Jupyter, A Platform for Data Science at Scale
Pytorch Ecosystem Day: The 珞 Ecosystem
PyTorch - an ecosystem for deep learning with Soumith Chintala (Facebook AI)
Zeppelin, TensorFlow, Deep Learning 맛보기
Puppet Camp Dallas 2014: How Puppet Ops Rolls
Real Time Graph Computations in Storm, Neo4J, Python - PyCon India 2013
Realtime processing with storm presentation
PharoDAYS 2015: Pharo Status - by Markus Denker
Pharo4: Plans and Dreams
SciPy 2019: How to Accelerate an Existing Codebase with Numba
Protocol libraries the right way
Creating Art with a Raspberry Pi - Stephanie Nemeth - Codemotion Amsterdam 2017
Numba lightning
Scale up and Scale Out Anaconda and PyData
Ad

Similar to C# - Raise the bar with functional & immutable constructs (Dutch) (20)

PPTX
Functional Programming
PDF
Functional Programming in C#
PPTX
Why functional programming in C# & F#
PPTX
Functional programming
PDF
Functional programming & immutable data.
PDF
Get Functional on the CLR: Intro to Functional Programming with F#
PDF
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...
PDF
Booting into functional programming
PPTX
Столпы функционального программирования для адептов ООП, Николай Мозговой
PPTX
Игорь Фесенко "Direction of C# as a High-Performance Language"
PPTX
How Functional Programming Made Me A Better Developer
PDF
Look Mommy, No GC! (TechDays NL 2017)
PPTX
Introduction to Functional Programming
PDF
Functional Programming in C# and F#
PPTX
FP Day 2011 - Turning to the Functional Side (using C# & F#)
PPTX
Intro to Functional Programming
PPTX
Functional Programming in C#
PPSX
Functional patterns and techniques in C#
PPTX
Intro f# functional_programming
PPTX
Improving app performance using .Net Core 3.0
Functional Programming
Functional Programming in C#
Why functional programming in C# & F#
Functional programming
Functional programming & immutable data.
Get Functional on the CLR: Intro to Functional Programming with F#
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...
Booting into functional programming
Столпы функционального программирования для адептов ООП, Николай Мозговой
Игорь Фесенко "Direction of C# as a High-Performance Language"
How Functional Programming Made Me A Better Developer
Look Mommy, No GC! (TechDays NL 2017)
Introduction to Functional Programming
Functional Programming in C# and F#
FP Day 2011 - Turning to the Functional Side (using C# & F#)
Intro to Functional Programming
Functional Programming in C#
Functional patterns and techniques in C#
Intro f# functional_programming
Improving app performance using .Net Core 3.0
Ad

More from Rick Beerendonk (6)

PDF
JavaScript 2016 for C# Developers
PPTX
Perform like an Olympian
PPTX
JavaScript innovaties: ECMAScript 6 & 7
PPTX
ReactJS.NET - Fast and Scalable Single Page Applications
PPTX
ReactJS maakt het web eenvoudig
PPTX
Niet onderhoudbare software in 10 makkelijke stappen
JavaScript 2016 for C# Developers
Perform like an Olympian
JavaScript innovaties: ECMAScript 6 & 7
ReactJS.NET - Fast and Scalable Single Page Applications
ReactJS maakt het web eenvoudig
Niet onderhoudbare software in 10 makkelijke stappen

Recently uploaded (20)

PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Digital Strategies for Manufacturing Companies
PPTX
L1 - Introduction to python Backend.pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
System and Network Administration Chapter 2
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Essential Infomation Tech presentation.pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Introduction to Artificial Intelligence
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Digital Strategies for Manufacturing Companies
L1 - Introduction to python Backend.pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
System and Network Administration Chapter 2
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Essential Infomation Tech presentation.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
Which alternative to Crystal Reports is best for small or large businesses.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Reimagine Home Health with the Power of Agentic AI​
Introduction to Artificial Intelligence
Upgrade and Innovation Strategies for SAP ERP Customers
VVF-Customer-Presentation2025-Ver1.9.pptx
How to Migrate SBCGlobal Email to Yahoo Easily
CHAPTER 2 - PM Management and IT Context
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

C# - Raise the bar with functional & immutable constructs (Dutch)