Functional programming labs for C#/LINQ, F#, and JS
Welcome to Troy's functional programming labs prepared for the North Dallas .NET User Group. In these labs we will explore the concepts behind functional programming and apply them using C#, JavaScript, and F#.
Warning: not all of the code in the examples will compile. Sometimes this is deliberate, sometimes I just say its deliberate!
Why Do We Care?
- About doing more with less code
- Most FP code has 2x to 10x fewer lines of code than OOP
Other Reasons We Care
- Microservices
- Big Data
- Search
- Collections
- Research
- Startups
- All the cool kids are doing it
Where did this come from?
What happens when you code using FP
Even Neil DeGrasse Tyson gives you respect!
the basics...
Lists, Collections, Oh My!
Abstraction = Using Functions
- OOP abstracts low level operations into classes.
- FP abstracts away things like loops and interfaces
Most .NET developers already use some aspects of FP in tools such as LINQ, arrow functions, collections, etc
Expressions
Immutablity
Pure functions
- No side effects
- Returns the same output for the same input (singleton)
- Static functions = singletons
- Most complexity and bugs in an application are a result of pervasive use of state and side effects of stateful code
- Encapsulation
Anonymous Functions
Delegates
Lambdas
()=>
=>
Func<T,Tresult>
Levels of Abstraction
1. Abstraction level 0: no functions
-
Abstraction Level 1: First Order Functions
-
Abstraction Level 2: Higher Order Functions + Combinator Libraries
-
Abstraction Level 3: Typeclasses, Abstracting over Combinator Libraries
-
Abstraction Level 4: Abstracting over Typeclasses
The languages
Level 3 Functional Programming Site
Resources
Advanced Labs
Create your own big data processor with map/reduce