Table of Contents

Struct ValueOption<T>

Namespace
UniOption
Assembly
UniOption.dll
[Serializable]
public readonly struct ValueOption<T> : IOption, IEquatable<ValueOption<T>> where T : struct

Type Parameters

T
Implements
Inherited Members
Extension Methods

Fields

None

Gets a ValueOption with a None value.

public static readonly ValueOption<T> None

Field Value

ValueOption<T>

Properties

IsNone

Gets a value indicating whether this ValueOption has a None value.

[Pure]
public bool IsNone { get; }

Property Value

bool

IsSome

Gets a value indicating whether this ValueOption has a Some value.

[Pure]
public bool IsSome { get; }

Property Value

bool

Methods

Do(Action<T>)

Performs the specified action on the value of this ValueOption if it has a Some value.

public ValueOption<T> Do(Action<T> ifSome)

Parameters

ifSome Action<T>

The action to perform if this ValueOption has a Some value.

Returns

ValueOption<T>

This ValueOption.

Do(Action<T>, Action)

Performs the specified actions on the value of this ValueOption based on whether it has a Some value or a None value.

public ValueOption<T> Do(Action<T> ifSome, Action ifNone)

Parameters

ifSome Action<T>

The action to perform if this ValueOption has a Some value.

ifNone Action

The action to perform if this ValueOption has a None value.

Returns

ValueOption<T>

This ValueOption.

DoAsync(Func<T, UniTask>)

Asynchronously performs the specified async action on the value of this ValueOption if it has a Some value.

public UniTask<ValueOption<T>> DoAsync(Func<T, UniTask> ifSome)

Parameters

ifSome Func<T, UniTask>

The async action to perform if this ValueOption has a Some value.

Returns

UniTask<ValueOption<T>>

A UniTask representing the asynchronous operation.

DoAsync(Func<T, UniTask>, Func<UniTask>)

Asynchronously performs the specified async actions on the value of this ValueOption based on whether it has a Some value or a None value.

public UniTask<ValueOption<T>> DoAsync(Func<T, UniTask> ifSome, Func<UniTask> ifNone)

Parameters

ifSome Func<T, UniTask>

The async action to perform if this ValueOption has a Some value.

ifNone Func<UniTask>

The async action to perform if this ValueOption has a None value.

Returns

UniTask<ValueOption<T>>

A UniTask representing the asynchronous operation.

Do<TContext>(Action<T, TContext>, TContext)

Performs the specified actions on the value of this Option based on whether it has a Some value or a None value.

public ValueOption<T> Do<TContext>(Action<T, TContext> ifSome, TContext context)

Parameters

ifSome Action<T, TContext>

The action to perform if this Option has a Some value.

context TContext

The context to pass to the action.

Returns

ValueOption<T>

This Option.

Type Parameters

TContext

Do<TContext>(Action<T, TContext>, TContext, Action<TContext>)

Performs the specified action, with a value reference to a context, on the value of this Option based on whether it has a Some value or a None value.

public ValueOption<T> Do<TContext>(Action<T, TContext> ifSome, TContext context, Action<TContext> ifNone)

Parameters

ifSome Action<T, TContext>

The action to perform if this Option has a Some value.

context TContext

The context to pass to the action.

ifNone Action<TContext>

The action to perform if this Option has a None value.

Returns

ValueOption<T>

This Option.

Type Parameters

TContext

Do<TContext>(ActionRef<T, TContext>, ref TContext)

Performs the specified action, with a mutable reference to a context, on the value of this Option based on whether it has a Some value or a None value.

public ValueOption<T> Do<TContext>(ActionRef<T, TContext> ifSome, ref TContext context)

Parameters

ifSome ActionRef<T, TContext>

The action to perform if this Option has a Some value.

context TContext

The context to pass to the action.

Returns

ValueOption<T>

This Option.

Type Parameters

TContext

Do<TContext>(ActionRef<T, TContext>, ref TContext, ActionRef<TContext>)

Performs the specified action, with a mutable reference to a context, on the value of this Option based on whether it has a Some value or a None value.

public ValueOption<T> Do<TContext>(ActionRef<T, TContext> ifSome, ref TContext context, ActionRef<TContext> ifNone)

Parameters

ifSome ActionRef<T, TContext>

The action to perform if this Option has a Some value.

context TContext

The context to pass to the action.

ifNone ActionRef<TContext>

The action to perform if this Option has a None value.

Returns

ValueOption<T>

This Option.

Type Parameters

TContext

Equals(object?)

public override bool Equals(object? other)

Parameters

other object

Returns

bool

Equals(ValueOption<T>)

public bool Equals(ValueOption<T> other)

Parameters

other ValueOption<T>

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

IsSomeAnd(Func<T, bool>)

Checks if this ValueOption has a Some value and satisfies the given predicate.

public bool IsSomeAnd(Func<T, bool> predicate)

Parameters

predicate Func<T, bool>

The predicate to check.

Returns

bool

True if this ValueOption has a Some value and satisfies the predicate; otherwise, false.

MapObject<TResult>(Func<T, TResult>)

Applies a mapping function to the value of this ValueOption and returns a new Option with the result.

[Pure]
public Option<TResult> MapObject<TResult>(Func<T, TResult> map) where TResult : class

Parameters

map Func<T, TResult>

The mapping function.

Returns

Option<TResult>

An Option with the mapped value if this ValueOption has a Some value; otherwise, an Option with a None value.

Type Parameters

TResult

The type of the result value.

Map<TResult>(Func<T, TResult>)

Applies a mapping function to the value of this ValueOption and returns a new ValueOption with the result.

[Pure]
public ValueOption<TResult> Map<TResult>(Func<T, TResult> map) where TResult : struct

Parameters

map Func<T, TResult>

The mapping function.

Returns

ValueOption<TResult>

A ValueOption with the mapped value if this ValueOption has a Some value; otherwise, a ValueOption with a None value.

Type Parameters

TResult

The type of the result value.

Match<TResult>(Func<T, TResult>, Func<TResult>)

Matches the value of this ValueOption and applies the specified functions accordingly.

public TResult Match<TResult>(Func<T, TResult> some, Func<TResult> none)

Parameters

some Func<T, TResult>

The function to apply if this ValueOption has a Some value.

none Func<TResult>

The function to apply if this ValueOption has a None value.

Returns

TResult

The result of applying the specified function to the value of this ValueOption.

Type Parameters

TResult

The 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

some Func<T, TContext, TResult>

The function to apply if this Option has a Some value.

context TContext

The context to pass to the function.

none Func<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

TResult

The type of the result.

TContext

The 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

some Func<T, TContext, TResult>

The function to apply if this Option has a Some value.

context TContext

The context to pass to the function.

none Func<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

TResult

The type of the result.

TContext

The type of the context.

Or(T)

Returns this ValueOption if it has a Some value; otherwise, returns the specified alternative option.

[Pure]
public ValueOption<T> Or(T orOption)

Parameters

orOption T

The alternative option to return if this ValueOption has a None value.

Returns

ValueOption<T>

This ValueOption if it has a Some value; otherwise, the specified alternative option.

Reduce()

Returns the value of this ValueOption if it has a Some value; otherwise, returns the default value of type T.

[Pure]
public T Reduce()

Returns

T

The value of this ValueOption if it has a Some value; otherwise, the default value of type T.

Reduce(Func<T>)

Returns the value of this ValueOption if it has a Some value; otherwise, returns the value returned by the specified function.

public T Reduce(Func<T> ifNone)

Parameters

ifNone Func<T>

The function that returns the value to return if this ValueOption has a None value.

Returns

T

The value of this ValueOption if it has a Some value; otherwise, the value returned by the specified function.

Reduce(T)

Returns the value of this ValueOption if it has a Some value; otherwise, returns the specified value.

[Pure]
public T Reduce(T ifNone)

Parameters

ifNone T

The value to return if this ValueOption has a None value.

Returns

T

The value of this ValueOption if it has a Some value; otherwise, the specified value.

Some(T)

Creates a new ValueOption with a Some value.

[Pure]
public static ValueOption<T> Some(T obj)

Parameters

obj T

The value to wrap.

Returns

ValueOption<T>

A ValueOption with the specified value.

ToEnumerable()

Converts this ValueOption to an enumerable containing the value if it has a Some value; otherwise, returns an empty enumerable.

[Pure]
public IEnumerable<T> ToEnumerable()

Returns

IEnumerable<T>

An enumerable containing the value of this ValueOption if it has a Some value; otherwise, an empty enumerable.

ToString()

public override string ToString()

Returns

string

Where(Func<T, bool>)

Filters the value of this ValueOption based on the given predicate.

public ValueOption<T> Where(Func<T, bool> predicate)

Parameters

predicate Func<T, bool>

The predicate to filter the value.

Returns

ValueOption<T>

This ValueOption if it has a None value or the value satisfies the predicate; otherwise, a ValueOption with a None value.

WhereNot(Func<T, bool>)

Filters the value of this ValueOption based on the given predicate.

public ValueOption<T> WhereNot(Func<T, bool> predicate)

Parameters

predicate Func<T, bool>

The predicate to filter the value.

Returns

ValueOption<T>

This ValueOption if it has a None value or the value does not satisfy the predicate; otherwise, a ValueOption with a None value.

Zip<T2>(Option<T2>)

Combines the value of this ValueOption with the value of the specified Option into a ValueOption.

[Pure]
public ValueOption<(T, T2)> Zip<T2>(Option<T2> other) where T2 : class

Parameters

other Option<T2>

The other Option to zip.

Returns

ValueOption<(T, T2)>

A ValueOption with a tuple of the values if both ValueOptions have Some values; otherwise, a ValueOption with a None value.

Type Parameters

T2

The type of the value in the other Option.

Zip<T2>(T2)

Combines the value of this ValueOption with the specified value into a ValueOption.

[Pure]
public ValueOption<(T, T2)> Zip<T2>(T2 other) where T2 : struct

Parameters

other T2

The specified value to zip.

Returns

ValueOption<(T, T2)>

A ValueOption with a tuple of the values if this ValueOption has a Some value; otherwise, a ValueOption with a None value.

Type Parameters

T2

The type of the specified value.

Operators

operator ==(ValueOption<T>, ValueOption<T>)

public static bool operator ==(ValueOption<T> a, ValueOption<T> b)

Parameters

a ValueOption<T>
b ValueOption<T>

Returns

bool

implicit operator ValueOption<T>(T)

[Pure]
public static implicit operator ValueOption<T>(T content)

Parameters

content T

Returns

ValueOption<T>

operator !=(ValueOption<T>, ValueOption<T>)

public static bool operator !=(ValueOption<T> a, ValueOption<T> b)

Parameters

a ValueOption<T>
b ValueOption<T>

Returns

bool