DotNext by .NET Foundation and Contributors

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

.NET API 466,904 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 None.

public static Optional<T> Create<T, TMonad>(TMonad value) where TMonad : struct, IOptionMonad<T>

Converts the monad to Optional<T>.

public static Optional<T> Flatten<T>(this ref Optional optional)

Flattens the nested optional value.

public static T& modreq(System.Runtime.InteropServices.InAttribute) GetReference<T, TException>(ref Optional optional) where T : struct where TException : Exception

Obtains immutable reference to the value in the container.

public static T& modreq(System.Runtime.InteropServices.InAttribute) GetReference<T>(ref Optional optional, Func<Exception> exceptionFactory) where T : struct

Obtains immutable reference to the value in the container.

public static T& modreq(System.Runtime.InteropServices.InAttribute) GetReference<T>(ref Optional optional, method exceptionFactory) where T : struct

public static T& modreq(System.Runtime.InteropServices.InAttribute) GetReference<T>(ref Optional optional) where T : struct

Obtains immutable reference to the value in the container.

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 Optional<T> None<T>()

Returns empty value.

public static Optional<T> Null<T>()

Wraps null value to Optional<T> container.

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> Some<T>(T value)

Wraps the value to Optional<T> container.

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

Constructs optional value from nullable reference type.