public static Option<T> NoneGets an Option<T> representing the absence of a value.
All Types / Ferrous.Results
public readonly struct Option<T> : IEquatable<Option<T>>, IOptionValue
Represents an optional value: every Option<T> is either Some containing a value, or None containing no value. Equivalent to Rust's Option<T>.
Tpublic static Option<T> NoneGets an Option<T> representing the absence of a value.
public bool IsSomeGets a value indicating whether this option contains a value.
public bool IsNoneGets a value indicating whether this option does not contain a value.
public static Option<T> Some(T value)Creates an Option<T> containing value.
valuepublic bool TryGetValue([MaybeNullWhen(false)] out T value)Attempts to retrieve the contained value without throwing.
valuetrue, contains the wrapped value.public T Unwrap()Returns the contained value, throwing InvalidOperationException if None.
public T Expect(string message)Returns the contained value, throwing InvalidOperationException with message if None.
public T UnwrapOr(T defaultValue)Returns the contained value or defaultValue if None.
public T UnwrapOrElse(Func<T> fallback)Returns the contained value or computes a fallback via fallback if None.
public Option<TResult> Map<TResult>(Func<T, TResult> selector)Maps an Option<T> to Option<TResult> by applying selector if Some.
public Option<TResult> AndThen<TResult>(Func<T, Option<TResult>> binder)Chains another option-producing operation if Some; otherwise propagates None.
public Option<T> Filter(Func<T, bool> predicate)Returns None if the option is None or if predicate returns false.
public TResult Match<TResult>(Func<T, TResult> onSome, Func<TResult> onNone)Exhaustively matches both Some and None branches, returning a value.
public void Match(Action<T> onSome, Action onNone)Exhaustively matches both Some and None branches for side effects.
public Result<T, TError> OkOr<TError>(TError error)Transforms this Option<T> into a Result<T, TError>, mapping Some(v) to Ok(v) and None to Err(error).
public Result<T, TError> OkOrElse<TError>(Func<TError> errorFactory)Transforms this Option<T> into a Result<T, TError>, lazily computing the error when None.
public bool Equals(Option<T> other)public override bool Equals(object? obj)public override int GetHashCode()public override string ToString()