Option<T> Struct
Definition
- Namespace
- Tyne
- Assembly
- Tyne.Core.dll
An option encapsulates either Some(
or T
)None
.
[JsonConverter(typeof(OptionJsonConverterFactory))]
public readonly struct Option<T> : IEquatable<Option<T>>, IEquatable<T>
Type Parameters
T
The type of value this option encapsulates.
- Implements
-
IEquatable<Option<T>>IEquatable<T>
Remarks
The purpose of Option<T> is to provide a strong construct for handling the None case. This encourages consumers to consider how to handle a missing value, rather than assuming the happy path.
In functional terms, this is a polymorphic union which encapsulates either Some(
or T
)None
.
See Option for how to create Option<T>s.
Some(42)
is considered equal to Some(42)
and 42
.
None<int?>
is considered equal to None<int?>
and null.
Constructors
Option() | Creates an empty Option<T>. |
Methods
Equals(in Option<T>?) | Determines whether the specified Option<T> |
Equals(object?) | Determines whether the specified |
Equals(in Option<T>) | Determines whether the specified Option<T> |
Equals(T?) | Determines whether the specified |
GetHashCode() | Returns a hash code for this instance. |
ToString() | Returns a string that represents this instance. |
TryUnwrap(out T?) | Tries to unwrap this option. |
Operators
operator ==(in Option<T>, in Option<T>) | Determines whether |
operator ==(in Option<T>, T?) | Determines whether |
operator ==(T?, in Option<T>) | Determines whether |
implicit operator Option<T>(in T?) | Wraps |
operator !=(in Option<T>, in Option<T>) | Determines whether |
operator !=(in Option<T>, T?) | Determines whether |
operator !=(T?, in Option<T>) | Determines whether |