Various extension and factory methods for constructing optional value.
Namespace: DotNext Assembly: DotNext.dll Syntaxpublic static class Optional
Methods | Edit this page View Source Coalesce<T>(in Optional<T>, in Optional<T>)
Returns the second value if the first is empty.
Declarationpublic static ref readonly Optional<T> Coalesce<T>(this in Optional<T> first, in Optional<T> second)
Parameters Type Name Description Optional<T> first
The first optional value.
Optional<T> secondThe second optional value.
Returns Type Description Optional<T>The second value if the first is empty; otherwise, the first value.
Type Parameters Name Description TType of value.
| Edit this page View Source Convert<TInput, TOutput>(Task<Optional<TInput>>, Converter<TInput, TOutput>)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.
Declarationpublic static Task<Optional<TOutput>> Convert<TInput, TOutput>(this Task<Optional<TInput>> task, Converter<TInput, TOutput> converter)
Parameters Type Name Description Task<Optional<TInput>> task
The task containing Optional value.
Converter<TInput, TOutput> converterA mapping function to be applied to the value, if present.
Returns Type Description Task<Optional<TOutput>>An Optional describing the result of applying a mapping function to the value of this Optional, if a value is present, otherwise None.
Type Parameters Name Description TInputThe type of stored in the Optional container.
TOutputThe type of the mapping function result.
| Edit this page View Source Convert<TInput, TOutput>(Task<Optional<TInput>>, Func<TInput, CancellationToken, Task<TOutput>>, CancellationToken)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.
Declarationpublic static Task<Optional<TOutput>> Convert<TInput, TOutput>(this Task<Optional<TInput>> task, Func<TInput, CancellationToken, Task<TOutput>> converter, CancellationToken token = default)
Parameters Type Name Description Task<Optional<TInput>> task
The task containing Optional value.
Func<TInput, CancellationToken, Task<TOutput>> converterA mapping function to be applied to the value, if present.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description Task<Optional<TOutput>>An Optional describing the result of applying a mapping function to the value of this Optional, if a value is present, otherwise None.
Type Parameters Name Description TInputThe type of stored in the Optional container.
TOutputThe type of the mapping function result.
| Edit this page View Source Flatten<T>(in Optional<Optional<T>>)Flattens the nested optional value.
Declarationpublic static Optional<T> Flatten<T>(this in Optional<Optional<T>> optional)
Parameters Returns Type Description Optional<T>
Flattened value.
Type Parameters Name Description TThe type of the underlying value.
| Edit this page View Source Flatten<T>(Task<Optional<T>>)Returns a task that contains unwrapped value; or exception if Optional<T> has no value.
Declarationpublic static Task<T> Flatten<T>(this Task<Optional<T>> task)
Parameters Type Name Description Task<Optional<T>> task
The task representing optional value.
Returns Type Description Task<T>The task containing a value of type T
; or the exception if Optional<T> has no value.
The type of the value.
Exceptions | Edit this page View Source GetUnderlyingType(Type)Returns the underlying type argument of the specified optional type.
Declarationpublic static Type? GetUnderlyingType(Type optionalType)
Parameters Type Name Description Type optionalType
Optional type.
Returns Type Description TypeUnderlying type argument of the optional type; otherwise, null.
| Edit this page View Source If<T>(Task<Optional<T>>, Predicate<T>)If a value is present, and the value matches the given predicate, return an Optional describing the value, otherwise return an empty Optional.
Declarationpublic static Task<Optional<T>> If<T>(this Task<Optional<T>> task, Predicate<T> condition)
Parameters Type Name Description Task<Optional<T>> task
The task returning optional value.
Predicate<T> conditionA predicate to apply to the value, if present.
Returns Type Description Task<Optional<T>>An Optional describing the value of this Optional if a value is present and the value matches the given predicate, otherwise an empty Optional.
Type Parameters Name Description TType of the value.
| Edit this page View Source IsOptional(Type)Indicates that specified type is optional type.
Declarationpublic static bool IsOptional(this Type optionalType)
Parameters Type Name Description Type optionalType
The type to check.
Returns Type Description booltrue, if specified type is optional type; otherwise, false.
| Edit this page View Source None<T>()Returns empty value.
Declarationpublic static Optional<T> None<T>()
Returns Type Description Optional<T>
The empty value.
Type Parameters Name Description TThe type of empty result.
| Edit this page View Source Null<T>()Wraps null value to Optional<T> container.
Declarationpublic static Optional<T> Null<T>() where T : class?
Returns Type Parameters Name Description T
The reference type.
| Edit this page View Source OrDefault<T>(Task<Optional<T>>)If a value is present, returns the value, otherwise return default value.
Declarationpublic static Task<T?> OrDefault<T>(this Task<Optional<T>> task)
Parameters Type Name Description Task<Optional<T>> task
The task returning optional value.
Returns Type Description Task<T>The value stored in the container, if present, otherwise default value.
Type Parameters Name Description TType of the value.
| Edit this page View Source OrInvoke<T>(Task<Optional<T>>, Func<T>)Returns the value if present; otherwise invoke delegate.
Declarationpublic static Task<T> OrInvoke<T>(this Task<Optional<T>> task, Func<T> defaultFunc)
Parameters Type Name Description Task<Optional<T>> task
The task returning optional value.
Func<T> defaultFuncA delegate to be invoked if value is not present.
Returns Type Description Task<T>The value, if present, otherwise returned from delegate.
Type Parameters Name Description TType of the value.
| Edit this page View Source OrNull<T>(in Optional<T>)If a value is present, returns the value, otherwise null.
Declarationpublic static T? OrNull<T>(this in Optional<T> value) where T : struct
Parameters Type Name Description Optional<T> value
Optional value.
Returns Type Description T?Nullable value.
Type Parameters Name Description TValue type.
| Edit this page View Source OrNull<T>(Task<Optional<T>>)If a value is present, returns the value, otherwise null.
Declarationpublic static Task<T?> OrNull<T>(this Task<Optional<T>> task) where T : struct
Parameters Type Name Description Task<Optional<T>> task
The task returning optional value.
Returns Type Description Task<T?>Nullable value.
Type Parameters Name Description TThe type of the value.
| Edit this page View Source OrThrow<T, TException>(Task<Optional<T>>)If a value is present, returns the value, otherwise throw exception.
Declarationpublic static Task<T> OrThrow<T, TException>(this Task<Optional<T>> task) where TException : Exception, new()
Parameters Type Name Description Task<Optional<T>> task
The task returning optional value.
Returns Type Description Task<T>The value, if present.
Type Parameters Name Description TType of the value.
TExceptionType of exception to throw.
| Edit this page View Source OrThrow<T, TException>(Task<Optional<T>>, Func<TException>)If a value is present, returns the value, otherwise throw exception.
Declarationpublic static Task<T> OrThrow<T, TException>(this Task<Optional<T>> task, Func<TException> exceptionFactory) where TException : Exception
Parameters Type Name Description Task<Optional<T>> task
The task returning optional value.
Func<TException> exceptionFactoryException factory.
Returns Type Description Task<T>The value, if present.
Type Parameters Name Description TType of the value.
TExceptionType of exception to throw.
| Edit this page View Source Or<T>(Task<Optional<T>>, T?)Returns the value if present; otherwise return default value.
Declarationpublic static Task<T?> Or<T>(this Task<Optional<T>> task, T? defaultValue)
Parameters Type Name Description Task<Optional<T>> task
The task returning optional value.
T defaultValueThe value to be returned if there is no value present.
Returns Type Description Task<T>The value, if present, otherwise default.
Type Parameters Name Description TThe type of the value.
| Edit this page View Source Some<T>(T)Wraps the value to Optional<T> container.
Declarationpublic static Optional<T> Some<T>(T value)
Parameters Type Name Description T value
The value to be wrapped.
Returns Type Description Optional<T>The optional container.
Type Parameters Name Description TThe type of the value.
| Edit this page View Source ToOptional<T>(in T?)Constructs optional value from nullable value type.
Declarationpublic static Optional<T> ToOptional<T>(this in T? value) where T : struct
Parameters Type Name Description T? value
The value to convert.
Returns Type Description Optional<T>The value wrapped into Optional container.
Type Parameters Name Description TType of value.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4