Struct SerializableOption<T>
- Namespace
- UniOption
- Assembly
- UniOption.dll
[Serializable]
public struct SerializableOption<T> : IOption where T : class
Type Parameters
T
- Implements
- Inherited Members
- Extension Methods
Fields
None
Gets an Option with a None value.
public static readonly Option<T> None
Field Value
- Option<T>
Properties
IsNone
True if this Option has a None value; otherwise, false.
[Pure]
public bool IsNone { get; }
Property Value
IsSome
True if this Option has a Some value; otherwise, false.
[Pure]
public bool IsSome { get; }
Property Value
Methods
Do(Action<T>)
Performs the specified action on the value of this Option if it has a Some value.
public Option<T> Do(Action<T> ifSome)
Parameters
ifSomeAction<T>The action to perform if this Option has a Some value.
Returns
- Option<T>
This Option.
Do(Action<T>, Action)
Performs the specified actions on the value of this Option based on whether it has a Some value or a None value.
public Option<T> Do(Action<T> ifSome, Action ifNone)
Parameters
ifSomeAction<T>The action to perform if this Option has a Some value.
ifNoneActionThe action to perform if this Option has a None value.
Returns
- Option<T>
This Option.
DoAsync(Func<T, UniTask>)
Asynchronously performs the specified async action on the value of this Option if it has a Some value.
[Pure]
public UniTask<Option<T>> DoAsync(Func<T, UniTask> ifSome)
Parameters
ifSomeFunc<T, UniTask>The async action to perform if this Option has a Some value.
Returns
- UniTask<Option<T>>
A UniTask representing the asynchronous operation.
DoAsync(Func<T, UniTask>, Func<UniTask>)
Asynchronously performs the specified async actions on the value of this Option based on whether it has a Some value or a None value.
public UniTask<Option<T>> DoAsync(Func<T, UniTask> ifSome, Func<UniTask> ifNone)
Parameters
ifSomeFunc<T, UniTask>The async action to perform if this Option has a Some value.
ifNoneFunc<UniTask>The async action to perform if this Option has a None value.
Returns
- UniTask<Option<T>>
A UniTask representing the asynchronous operation.
Do<TContext>(Action<T, TContext>, TContext, Action<TContext>)
Performs the specified actions on the value of this Option based on whether it has a Some value or a None value.
public Option<T> Do<TContext>(Action<T, TContext> ifSome, TContext context, Action<TContext> ifNone)
Parameters
ifSomeAction<T, TContext>The action to perform if this Option has a Some value.
contextTContextifNoneAction<TContext>The action to perform if this Option has a None value.
Returns
- Option<T>
This Option.
Type Parameters
TContext
Equals(object)
public override bool Equals(object obj)
Parameters
objobject
Returns
Equals(SerializableOption<T>)
public bool Equals(SerializableOption<T> other)
Parameters
otherSerializableOption<T>
Returns
GetHashCode()
public override int GetHashCode()
Returns
IsSomeAnd(Func<T, bool>)
Checks if this Option has a Some value and satisfies the given predicate.
public bool IsSomeAnd(Func<T, bool> predicate)
Parameters
predicateFunc<T, bool>The predicate to check.
Returns
- bool
True if this Option has a Some value and satisfies the predicate; otherwise, false.
MapValue<TResult>(Func<T, TResult>)
Applies a mapping function to the value of this Option and returns a new ValueOption with the result.
[Pure]
public ValueOption<TResult> MapValue<TResult>(Func<T, TResult> map) where TResult : struct
Parameters
mapFunc<T, TResult>The mapping function.
Returns
- ValueOption<TResult>
A ValueOption with the mapped value if this Option has a Some value; otherwise, a ValueOption with a None value.
Type Parameters
TResultThe type of the result value.
Map<TResult>(Func<T, TResult>)
Applies a mapping function to the value of this Option and returns a new Option with the result.
[Pure]
public Option<TResult> Map<TResult>(Func<T, TResult> map) where TResult : class
Parameters
mapFunc<T, TResult>The mapping function.
Returns
- Option<TResult>
An Option with the mapped value if this Option has a Some value; otherwise, an Option with a None value.
Type Parameters
TResultThe type of the result value.
Match<TResult>(Func<T, TResult>, Func<TResult>)
Matches the value of this Option and applies the specified functions accordingly.
public TResult Match<TResult>(Func<T, TResult> some, Func<TResult> none)
Parameters
someFunc<T, TResult>The function to apply if this Option has a Some value.
noneFunc<TResult>The function to apply if this Option has a None value.
Returns
- TResult
The result of applying the specified function to the value of this Option.
Type Parameters
TResultThe type of the result.
Match<TResult, TContext>(Func<T, TContext, TResult>, TContext, Func<TResult>)
Matches the value of this Option and applies the specified functions accordingly.
public TResult Match<TResult, TContext>(Func<T, TContext, TResult> some, TContext context, Func<TResult> none)
Parameters
someFunc<T, TContext, TResult>The function to apply if this Option has a Some value.
contextTContextThe context to pass to the function.
noneFunc<TResult>The function to apply if this Option has a None value.
Returns
- TResult
The result of applying the specified function to the value of this Option.
Type Parameters
TResultThe type of the result.
TContextThe type of the context.
Match<TResult, TContext>(Func<T, TContext, TResult>, TContext, Func<TContext, TResult>)
Matches the value of this Option and applies the specified functions accordingly.
public TResult Match<TResult, TContext>(Func<T, TContext, TResult> some, TContext context, Func<TContext, TResult> none)
Parameters
someFunc<T, TContext, TResult>The function to apply if this Option has a Some value.
contextTContextThe context to pass to the function.
noneFunc<TContext, TResult>The function to apply if this Option has a None value.
Returns
- TResult
The result of applying the specified function to the value of this Option.
Type Parameters
TResultThe type of the result.
TContextThe type of the context.
OfType<TValue>()
Filters the value of this Option to the specified type.
[Pure]
public Option<TValue> OfType<TValue>() where TValue : class
Returns
- Option<TValue>
An Option with the value cast to the specified type if it has a Some value and satisfies the type constraint; otherwise, an Option with a None value.
Type Parameters
TValueThe type to filter the value.
Or(T)
Returns this Option if it has a Some value; otherwise, returns the specified alternative option.
[Pure]
public Option<T> Or(T orOption)
Parameters
orOptionTThe alternative option to return if this Option has a None value.
Returns
- Option<T>
This Option if it has a Some value; otherwise, the specified alternative option.
Reduce(Func<T>)
Returns the value of this Option if it has a Some value; otherwise, returns the value returned by the specified function. This method is unsafe as it may throw an exception if the specified function throws an exception. It is recommended to use Match<TResult>(Func<T, TResult>, Func<TResult>) instead.
public T Reduce(Func<T> defaultValue)
Parameters
defaultValueFunc<T>The function that returns the default value to return.
Returns
- T
The value of this Option if it has a Some value; otherwise, the value returned by the specified function.
Reduce(T)
Returns the value of this Option if it has a Some value; otherwise, returns the specified default value.
[Pure]
public T Reduce(T defaultValue)
Parameters
defaultValueTThe default value to return.
Returns
- T
The value of this Option if it has a Some value; otherwise, the specified default value.
Some(T)
Creates a new Option with a Some value.
public static SerializableOption<T> Some(T content)
Parameters
contentTThe value to wrap.
Returns
- SerializableOption<T>
An Option with the specified value.
ToEnumerable()
Converts this Option to an enumerable containing the value if it has a Some value; otherwise, returns an empty enumerable.
public IEnumerable<T> ToEnumerable()
Returns
- IEnumerable<T>
An enumerable containing the value of this Option if it has a Some value; otherwise, an empty enumerable.
ToString()
[Pure]
public override string ToString()
Returns
Where(Func<T, bool>)
Filters the value of this Option based on the given predicate. This method is unsafe as it may throw an exception if the specified function throws an exception. It is recommended to use Match<TResult>(Func<T, TResult>, Func<TResult>) instead.
public Option<T> Where(Func<T, bool> predicate)
Parameters
predicateFunc<T, bool>The predicate to filter the value.
Returns
- Option<T>
This Option if it has a None value or the value satisfies the predicate; otherwise, an Option with a None value.
WhereNot(Func<T, bool>)
Filters the value of this Option based on the given predicate.
public Option<T> WhereNot(Func<T, bool> predicate)
Parameters
predicateFunc<T, bool>The predicate to filter the value.
Returns
- Option<T>
This Option if it has a None value or the value does not satisfy the predicate; otherwise, an Option with a None value.
Zip<T2>(Option<T2>)
Combines the value of this Option with the value of the specified Option into a ValueOption.
[Pure]
public ValueOption<(T, T2)> Zip<T2>(Option<T2> other) where T2 : class
Parameters
otherOption<T2>The other Option to zip.
Returns
- ValueOption<(T, T2)>
A ValueOption with a tuple of the values if both Options have Some values; otherwise, a ValueOption with a None value.
Type Parameters
T2The type of the value in the other Option.
Zip<T2>(T2)
Combines the value of this Option with the specified value into a ValueOption.
[Pure]
public ValueOption<(T, T2)> Zip<T2>(T2 other) where T2 : struct
Parameters
otherT2The specified value to zip.
Returns
- ValueOption<(T, T2)>
A ValueOption with a tuple of the values if this Option has a Some value; otherwise, a ValueOption with a None value.
Type Parameters
T2The type of the specified value.
Operators
operator ==(SerializableOption<T>, SerializableOption<T>)
public static bool operator ==(SerializableOption<T> a, SerializableOption<T> b)
Parameters
aSerializableOption<T>bSerializableOption<T>
Returns
operator !=(SerializableOption<T>, SerializableOption<T>)
public static bool operator !=(SerializableOption<T> a, SerializableOption<T> b)
Parameters
aSerializableOption<T>bSerializableOption<T>