|
1 | | -# 🎯 Option<T> Functional Cheat Sheet |
| 1 | +# AStar Dev Functional Extensions |
2 | 2 |
|
3 | | -## 🧩 Option Overview |
| 3 | +## Overview |
4 | 4 |
|
5 | | -Represents a value that might exist (`Some`) or not (`None`), avoiding nulls and enabling functional composition. |
| 5 | +This project contains a bunch of classes and extension methods to facilitate a more functional approach to handling errors and optional objects. |
6 | 6 |
|
7 | | -```csharp |
8 | | -Option<int> maybeNumber = Option.Some(42); |
9 | | -Option<string> emptyName = Option.None<string>(); |
10 | | -``` |
| 7 | +## Cheat Sheets |
11 | 8 |
|
12 | | ---- |
| 9 | +### Result<T> and associated extensions |
13 | 10 |
|
14 | | -## 🏗 Construction |
| 11 | +Cheat sheet is [here](Readme-result.md) |
15 | 12 |
|
16 | | -| Syntax | Description | |
17 | | -|-----------------------------|-----------------------------------------| |
18 | | -| `Option.Some(value)` | Wraps a non-null value as `Some` | |
19 | | -| `Option.None<T>()` | Creates a `None` of type `T` | |
20 | | -| `value.ToOption()` | Converts value or default to Option | |
21 | | -| `value.ToOption(predicate)` | Converts only if predicate returns true | |
22 | | -| `nullable.ToOption()` | Converts nullable struct to Option | |
| 13 | +### Option<T> and associated extensions |
23 | 14 |
|
24 | | ---- |
| 15 | +Cheat sheet is [here](Readme-option.md) |
25 | 16 |
|
26 | | -## 🧪 Pattern Matching |
| 17 | +## Build and analysis |
27 | 18 |
|
28 | | -```csharp |
29 | | -option.Match( |
30 | | - some => $"Value: {some}", |
31 | | - () => "No value" |
32 | | -); |
33 | | -``` |
| 19 | +### GitHub build |
34 | 20 |
|
35 | | -Or via deconstruction: |
| 21 | +[](https://github.com/astar-development/astar-dev-functional-extensions/actions/workflows/dotnet.yml) |
36 | 22 |
|
37 | | -```csharp |
38 | | -var (isSome, value) = option; |
39 | | -``` |
| 23 | +### SonarQube details |
40 | 24 |
|
41 | | -Or with TryGet: |
42 | | - |
43 | | -```csharp |
44 | | -if (option.TryGetValue(out var value)) { /* use value */ } |
45 | | -``` |
46 | | - |
47 | | ---- |
48 | | - |
49 | | -## 🔧 Transformation |
50 | | - |
51 | | -| Method | Description | |
52 | | -|---------------------|---------------------------------------------| |
53 | | -| `Map(func)` | Transforms value inside Some | |
54 | | -| `Bind(func)` | Chains function that returns another Option | |
55 | | -| `ToResult(errorFn)` | Converts Option to `Result<T, TError>` | |
56 | | -| `ToNullable()` | Converts to nullable (structs only) | |
57 | | -| `ToEnumerable()` | Converts to `IEnumerable<T>` | |
58 | | - |
59 | | ---- |
60 | | - |
61 | | -## 🪄 LINQ Support |
62 | | - |
63 | | -```csharp |
64 | | -var result = |
65 | | - from name in Option.Some("Jason") |
66 | | - from greeting in Option.Some($"Hello, {name}") |
67 | | - select greeting; |
68 | | -``` |
69 | | - |
70 | | -Via `Select`, `SelectMany`, or `SelectAwait` (async LINQ) |
71 | | - |
72 | | ---- |
73 | | - |
74 | | -## 🔁 Async Support |
75 | | - |
76 | | -| Method | Description | |
77 | | -|------------------------------|-----------------------------------------------| |
78 | | -| `MapAsync(func)` | Awaits and maps value | |
79 | | -| `BindAsync(func)` | Awaits and chains async Option-returning func | |
80 | | -| `MatchAsync(onSome, onNone)` | Async pattern match | |
81 | | -| `SelectAwait(func)` | LINQ-friendly async projection | |
82 | | - |
83 | | ---- |
84 | | - |
85 | | -## 🧯 Fallbacks and Conversions |
86 | | - |
87 | | -```csharp |
88 | | -option.OrElse("fallback"); // returns value or fallback |
89 | | -option.OrThrow(); // throws if None |
90 | | -option.IsSome(); // true if Some |
91 | | -option.IsNone(); // true if None |
92 | | -``` |
93 | | - |
94 | | ---- |
95 | | - |
96 | | -## 🐛 Debugging & Output |
97 | | - |
98 | | -```csharp |
99 | | -option.ToString(); // Outputs "Some(value)" or "None" |
100 | | -``` |
101 | | - |
102 | | ---- |
| 25 | +| | | | | | |
| 26 | +|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 27 | +| [](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-functional-extensions) | [](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-functional-extensions) | [](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-functional-extensions) | [](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-functional-extensions) | [](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-functional-extensions) | |
| 28 | +| [](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-functional-extensions) | [](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-functional-extensions) | [](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-functional-extensions) | [](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-functional-extensions) | [](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-functional-extensions) | |
103 | 29 |
|
0 commit comments