Table of Contents

Option Class

Definition

Namespace
Bodu.Functional
Assembly
Bodu.Core.dll
Package
Bodu.Core 1.0.1
Source
Option.cs

Provides factory methods for creating Option<T> values with type inference at the call site.

public static class Option
Inheritance
Option
Inherited Members

Remarks

The members mirror the static surface of Option<T> so callers can write Option.Some(3) instead of Option<int>.Some(3), and add FromNullable<T>(T?) - the Nullable<T> lift that the implicit conversion on the generic type cannot express.

Methods

FromNullable<T>(T?)

Converts a nullable value type to an option, mapping null to None.

public static Option<T> FromNullable<T>(T? value) where T : struct

Parameters

value T?

The nullable value to lift.

Returns

Option<T>

Some(value.Value) when value has a value; otherwise None.

Type Parameters

T

The underlying value type.

Examples

int? parsed = TryParseOrNull(text);
Option<int> option = Option.FromNullable(parsed); // None when parsed is null

None<T>()

Returns the option of the specified type that carries no value.

public static Option<T> None<T>()

Returns

Option<T>

An option whose IsNone is true.

Type Parameters

T

The value type of the option.

Some<T>(T)

Creates an option carrying the specified non-null value.

public static Option<T> Some<T>(T value)

Parameters

value T

The value to wrap. Must not be null.

Returns

Option<T>

An option whose IsSome is true.

Type Parameters

T

The type of the value.

Exceptions

ArgumentNullException

value is null.

Applies to

ProductVersions
.NET8, 10