DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="2.9.6" />

.NET API 329,216 bytes

 Optional

public static class Optional
Various extension and factory methods for constructing optional value.
public static Optional Coalesce<T>(this ref Optional first, ref Optional second)

Returns the second value if the first is empty.

public static Task<Optional<TOutput>> Convert<TInput, TOutput>(this Task<Optional<TInput>> task, Converter<TInput, TOutput> converter)

If a value is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise returns Empty.

public static Type GetUnderlyingType(Type optionalType)

Returns the underlying type argument of the specified optional type.

public static Task<Optional<T>> If<T>(this Task<Optional<T>> task, Predicate<T> condition)

If a value is present, and the value matches the given predicate, return an Optional describing the value, otherwise return an empty Optional.

public static bool IsOptional(this Type optionalType)

Indicates that specified type is optional type.

public static Task<T> Or<T>(this Task<Optional<T>> task, T defaultValue)

Returns the value if present; otherwise return default value.

public static Task<T> OrDefault<T>(this Task<Optional<T>> task)

If a value is present, returns the value, otherwise return default value.

public static Task<T> OrInvoke<T>(this Task<Optional<T>> task, Func<T> defaultFunc)

Returns the value if present; otherwise invoke delegate.

public static Task<T?> OrNull<T>(this Task<Optional<T>> task) where T : struct

If a value is present, returns the value, otherwise null.

public static T? OrNull<T>(this ref Optional value) where T : struct

If a value is present, returns the value, otherwise null.

public static Task<T> OrThrow<T, TException>(this Task<Optional<T>> task) where TException : Exception

If a value is present, returns the value, otherwise throw exception.

public static Task<T> OrThrow<T, TException>(this Task<Optional<T>> task, Func<TException> exceptionFactory) where TException : Exception

If a value is present, returns the value, otherwise throw exception.

public static Optional<T> ToOptional<T>(this ref Nullable value) where T : struct

Constructs optional value from nullable reference type.