|
1 | 1 | # Functional C# |
2 | 2 |
|
3 | | -* Examples based on following sources: |
| 3 | +## Definition of C# z WIKI |
| 4 | +* https://en.wikipedia.org/wiki/C_Sharp_(programming_language) |
| 5 | +* Multi-paradigm: structured, imperative, object-oriented, event-driven, task-driven, functional, generic, reflective, concurrent |
| 6 | +* https://www.amazon.com/Functional-Programming-write-better-code/dp/1617293954 |
| 7 | + |
| 8 | + |
| 9 | +## Already build in |
| 10 | +* Delegates and lambdas (C# 3) |
| 11 | +```csharp |
| 12 | +persons.Where(p => p.IsRetired) |
| 13 | +``` |
| 14 | + |
| 15 | +* Static usings (C# 6) |
| 16 | +```csharp |
| 17 | +using static System.Math; |
| 18 | +double result = Pow(2, 3); |
| 19 | +``` |
| 20 | + |
| 21 | +* Nonnullable (C# 8) |
| 22 | +```csharp |
| 23 | +string? nickname = null; |
| 24 | +``` |
| 25 | + |
| 26 | +* Immutables (record C# 9+) |
| 27 | +```csharp |
| 28 | +public record Person(string Name, DateOnly BirthDate); |
| 29 | +``` |
| 30 | + |
| 31 | +* Pattern matching (C# 7-11) |
| 32 | +```csharp |
| 33 | + if (obj is string s) ... |
| 34 | + if (person is { Age: > 18, Name: var n }) ... |
| 35 | + var result = shape switch |
| 36 | + { |
| 37 | + Circle c => "circle", |
| 38 | + _ => "Unknown shape" |
| 39 | + } |
| 40 | +``` |
| 41 | + |
| 42 | +## The good parts |
| 43 | +* Linq lambas (Dotnet 3.5 2007) - tragedie představená v roce 2017: lokální funkce |
| 44 | +* Exception handling (Try object) |
| 45 | +* Result Type (https://dotnet.github.io/dotNext/features/core/result.html) |
| 46 | +* Option instead of Null (https://dotnet.github.io/dotNext/features/core/optional.html) |
| 47 | +* Discriminated unions (Most awaited feature) https://www.youtube.com/watch?v=tD46WVJ2h9I&ab_channel=NickChapsas |
| 48 | +
|
| 49 | + |
| 50 | +## Examples Implementations |
| 51 | +* Used language-ext and OneOf nugets |
| 52 | +* Others: Functional.DotNet, Funcky, FunCs, Fambda, Farity or other exotic implementations like FuncSharp |
| 53 | + |
| 54 | + |
| 55 | +## Examples based on following sources |
4 | 56 | * [FuncSharp library](https://github.com/MewsSystems/FuncSharp) |
5 | 57 | * [The New Option and Result Types of C#](https://www.youtube.com/watch?v=aksjZkCbIWA) |
6 | 58 | * [Result pattern in medatr](https://goatreview.com/improving-error-handling-result-pattern-mediatr/) |
|
0 commit comments