Overview
Instead of nested null checks, use fluent transformations:Transformation
Select
Transform a nullable value:SelectMany
Transform with a selector that also returns nullable (flattens the result):Filtering
Where
Keep the value only if it satisfies a predicate:Side Effects
Do
Execute an action if not null, then continue the chain:Default Values
Or
Return the value or a default:OrElse
Return the value or compute a default lazily:OrThrow
Return the value or throw an exception:Pattern Matching
Match
Handle both cases explicitly:Collection Conversion
ToEnumerable
Convert a nullable to a single-element or empty sequence:Utility Methods
HasValue
Check if a reference type is not null:NullIf
Convert sentinel values to null:Examples
Safe Navigation
Configuration with Defaults
Validation Pipeline
Combining with LINQ
API Reference
Transformation
| Method | Description |
|---|---|
Select<T, TResult>(selector) | Transform value if not null |
SelectMany<T, TResult>(selector) | Transform with nullable selector (flattens) |
Filtering
| Method | Description |
|---|---|
Where<T>(predicate) | Keep value only if predicate is true |
Side Effects
| Method | Description |
|---|---|
Do<T>(action) | Execute action if not null, return original |
Default Values
| Method | Description |
|---|---|
Or<T>(default) | Return value or default |
OrElse<T>(factory) | Return value or factory result |
OrThrow<T>(exceptionFactory) | Return value or throw |
Pattern Matching
| Method | Description |
|---|---|
Match<T, TResult>(some, none) | Handle both cases |
ToEnumerable<T>() | Convert to single-element or empty sequence |
Utilities
| Method | Description |
|---|---|
HasValue<T>() | Returns true if not null (reference types) |
NullIf<T>(sentinel) | Returns null if equals sentinel (reference types) |
NullIfValue<T>(sentinel) | Returns null if equals sentinel (value types) |
