Table of Contents

Class Maybe

Namespace
Existential
Assembly
Existential.Net.dll

Provides utility methods for creating Maybe<T> instances, with or without values.

public static class Maybe
Inheritance
System.Object
Maybe
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()

Methods

WithKnownValue<T>(T)

Creates a Maybe<T> with the specified non-null value.

public static Maybe<T> WithKnownValue<T>(T inKnownValue)

Parameters

inKnownValue T

The non-null value to assign to the Maybe<T>.

Returns

Maybe<T>

A Maybe<T> with the value inKnownValue.

Type Parameters

T

The type of the value.

Remarks

This method can be used for creating a Maybe<T> in circumstances where it's important to fail fast (with an System.ArgumentNullException) if the value is null, but it needs to be wrapped as a Maybe<T> for compatibility with other processes.

Exceptions

System.ArgumentNullException

Thrown if the value, inKnownValue, is null.

WithValue<T>(T)

Creates a new instance of the Maybe<T> structure with the provided nullable value.

public static Maybe<T> WithValue<T>(T inValue)

Parameters

inValue T

The nullable value to be wrapped in a Maybe<T>. If null, a Empty will be returned.

Returns

Maybe<T>

A new instance of Maybe<T> wrapping the provided value, or Empty if the value is null.

Type Parameters

T

The type of the value to be wrapped.

Remarks

This overload supports creating a Maybe<T> from a nullable reference type.

WithValue<T>(Maybe<T>)

Returns the provided Maybe<T> structure unmodified, in order to prevent it being accidentally double-wrapped as a Maybe<Maybe<T>>.

public static Maybe<T> WithValue<T>(Maybe<T> inValue)

Parameters

inValue Maybe<T>

The Maybe<T> value which will be returned.

Returns

Maybe<T>

The provided Maybe<T> structure.

Type Parameters

T

The type of the wrapped value.

Remarks

This overload of the WithValue method prevents a Maybe<T> from being accidentally double-wrapped as a Maybe<Maybe<T>>.

WithValue<T>(Nullable<T>)

Creates a new instance of the Maybe<T> structure with the provided nullable value.

public static Maybe<T> WithValue<T>(T? inValue)

    where T : struct

Parameters

inValue System.Nullable<T>

The nullable value to be wrapped in a Maybe<T>. If null, a Empty will be returned.

Returns

Maybe<T>

A new instance of Maybe<T> wrapping the provided value, or Empty if the value is null.

Type Parameters

T

The type of the value to be wrapped.

Remarks

This overload supports creating a Maybe<T> from a nullable value type.

See Also