Tanoda
Leap.Unity.Maybe< T > Class Template Reference

A struct that represents a value that could or could not exist. Unlike the built-int nullable types, you are unable to access the value unless it does exist, and will never recieve a null value. More...

Inheritance diagram for Leap.Unity.Maybe< T >:

Classes

struct  NoneType
 

Public Member Functions

 Maybe (T t)
 Constructs a Maybe given a value. If the value is not null, this maybe will have a value. If the value is null, this maybe will have no value. For value types, the Maybe struct will always have a value. (Use Maybe.None to refer to "no value.") More...
 
bool TryGetValue (out T t)
 If this Maybe has a value, the out argument is filled with that value and this method returns true, else it returns false. More...
 
void Match (Action< T > ifValue)
 If this Maybe has a value, the delegate is called with that value. More...
 
void Match (Action< T > ifValue, Action ifNot)
 If this Maybe has a value, the first delegate is called with that value, else the second delegate is called. More...
 
Match< K > (Func< T, K > ifValue, Func< K > ifNot)
 If this Maybe has a value, the first delegate is called with that value, else the second delegate is called. More...
 
ValueOr (T customDefault)
 If this Maybe has a value, returns the value, otherwise returns the argument custom default value. More...
 
Maybe< T > ValueOr (Maybe< T > maybeCustomDefault)
 Returns this Maybe if it has a value, otherwise returns the argument Maybe value. Useful for overlaying multiple Maybe values. For example, if I want to overlay a "maybe override font" variable with another "maybe override font" variable, I can call: this.font = other.font.ValueOr(this.font); More...
 
Query< T > Query ()
 
override int GetHashCode ()
 
override bool Equals (object obj)
 
bool Equals (Maybe< T > other)
 
int CompareTo (object obj)
 
int CompareTo (Maybe< T > other)
 

Static Public Member Functions

static Maybe< T > Some< T > (T value)
 
static void MatchAll< A, B > (Maybe< A > maybeA, Maybe< B > maybeB, Action< A, B > action)
 
static void MatchAll< A, B, C > (Maybe< A > maybeA, Maybe< B > maybeB, Maybe< C > maybeC, Action< A, B, C > action)
 
static void MatchAll< A, B, C, D > (Maybe< A > maybeA, Maybe< B > maybeB, Maybe< C > maybeC, Maybe< D > maybeD, Action< A, B, C, D > action)
 
static Maybe< T > Some (T t)
 Constructs a Maybe given a specific value. This value needs to always be non-null if the type is a reference type. More...
 
static bool operator== (Maybe< T > maybe0, Maybe< T > maybe1)
 
static bool operator!= (Maybe< T > maybe0, Maybe< T > maybe1)
 
static bool operator> (Maybe< T > maybe0, Maybe< T > maybe1)
 
static bool operator>= (Maybe< T > maybe0, Maybe< T > maybe1)
 
static bool operator< (Maybe< T > maybe0, Maybe< T > maybe1)
 
static bool operator<= (Maybe< T > maybe0, Maybe< T > maybe1)
 
static implicit operator Maybe< T > (T t)
 
static implicit operator Maybe< T > (Maybe.NoneType none)
 

Public Attributes

readonly bool hasValue
 Returns whether or not this Maybe contains a value. More...
 

Static Public Attributes

static readonly NoneType None = new NoneType()
 
static readonly Maybe< T > None = new Maybe<T>()
 Returns a Maybe for this type that represents no value. More...
 

Properties

valueOrDefault [get]
 Gets the value, or the type's default if it doesn't exist. More...
 

Detailed Description

A struct that represents a value that could or could not exist. Unlike the built-int nullable types, you are unable to access the value unless it does exist, and will never recieve a null value.

Definition at line 59 of file Maybe.cs.

Constructor & Destructor Documentation

◆ Maybe()

Leap.Unity.Maybe< T >.Maybe ( t)

Constructs a Maybe given a value. If the value is not null, this maybe will have a value. If the value is null, this maybe will have no value. For value types, the Maybe struct will always have a value. (Use Maybe.None to refer to "no value.")

Definition at line 91 of file Maybe.cs.

Member Function Documentation

◆ CompareTo() [1/2]

int Leap.Unity.Maybe< T >.CompareTo ( Maybe< T >  other)

Definition at line 223 of file Maybe.cs.

◆ CompareTo() [2/2]

int Leap.Unity.Maybe< T >.CompareTo ( object  obj)

Definition at line 215 of file Maybe.cs.

◆ Equals() [1/2]

bool Leap.Unity.Maybe< T >.Equals ( Maybe< T >  other)

Definition at line 205 of file Maybe.cs.

◆ Equals() [2/2]

override bool Leap.Unity.Maybe< T >.Equals ( object  obj)

Definition at line 197 of file Maybe.cs.

◆ GetHashCode()

override int Leap.Unity.Maybe< T >.GetHashCode ( )

Definition at line 193 of file Maybe.cs.

◆ Match() [1/2]

void Leap.Unity.Maybe< T >.Match ( Action< T >  ifValue)

If this Maybe has a value, the delegate is called with that value.

Definition at line 124 of file Maybe.cs.

◆ Match() [2/2]

void Leap.Unity.Maybe< T >.Match ( Action< T >  ifValue,
Action  ifNot 
)

If this Maybe has a value, the first delegate is called with that value, else the second delegate is called.

Definition at line 134 of file Maybe.cs.

◆ Match< K >()

K Leap.Unity.Maybe< T >.Match< K > ( Func< T, K >  ifValue,
Func< K >  ifNot 
)

If this Maybe has a value, the first delegate is called with that value, else the second delegate is called.

Definition at line 146 of file Maybe.cs.

◆ MatchAll< A, B >()

static void Leap.Unity.Maybe< T >.MatchAll< A, B > ( Maybe< A >  maybeA,
Maybe< B >  maybeB,
Action< A, B >  action 
)
static

Definition at line 21 of file Maybe.cs.

◆ MatchAll< A, B, C >()

static void Leap.Unity.Maybe< T >.MatchAll< A, B, C > ( Maybe< A >  maybeA,
Maybe< B >  maybeB,
Maybe< C >  maybeC,
Action< A, B, C >  action 
)
static

Definition at line 29 of file Maybe.cs.

◆ MatchAll< A, B, C, D >()

static void Leap.Unity.Maybe< T >.MatchAll< A, B, C, D > ( Maybe< A >  maybeA,
Maybe< B >  maybeB,
Maybe< C >  maybeC,
Maybe< D >  maybeD,
Action< A, B, C, D >  action 
)
static

Definition at line 39 of file Maybe.cs.

◆ operator Maybe< T >() [1/2]

static implicit Leap.Unity.Maybe< T >.operator Maybe< T > ( Maybe< T >.NoneType  none)
static

Definition at line 271 of file Maybe.cs.

◆ operator Maybe< T >() [2/2]

static implicit Leap.Unity.Maybe< T >.operator Maybe< T > ( t)
static

Definition at line 267 of file Maybe.cs.

◆ operator!=()

static bool Leap.Unity.Maybe< T >.operator!= ( Maybe< T >  maybe0,
Maybe< T >  maybe1 
)
static

Definition at line 247 of file Maybe.cs.

◆ operator<()

static bool Leap.Unity.Maybe< T >.operator< ( Maybe< T >  maybe0,
Maybe< T >  maybe1 
)
static

Definition at line 259 of file Maybe.cs.

◆ operator<=()

static bool Leap.Unity.Maybe< T >.operator<= ( Maybe< T >  maybe0,
Maybe< T >  maybe1 
)
static

Definition at line 263 of file Maybe.cs.

◆ operator==()

static bool Leap.Unity.Maybe< T >.operator== ( Maybe< T >  maybe0,
Maybe< T >  maybe1 
)
static

Definition at line 243 of file Maybe.cs.

◆ operator>()

static bool Leap.Unity.Maybe< T >.operator> ( Maybe< T >  maybe0,
Maybe< T >  maybe1 
)
static

Definition at line 251 of file Maybe.cs.

◆ operator>=()

static bool Leap.Unity.Maybe< T >.operator>= ( Maybe< T >  maybe0,
Maybe< T >  maybe1 
)
static

Definition at line 255 of file Maybe.cs.

◆ Query()

Query< T > Leap.Unity.Maybe< T >.Query ( )

Definition at line 185 of file Maybe.cs.

◆ Some()

static Maybe< T > Leap.Unity.Maybe< T >.Some ( t)
static

Constructs a Maybe given a specific value. This value needs to always be non-null if the type is a reference type.

Definition at line 104 of file Maybe.cs.

◆ Some< T >()

static Maybe< T > Leap.Unity.Maybe< T >.Some< T > ( value)
static

Definition at line 17 of file Maybe.cs.

◆ TryGetValue()

bool Leap.Unity.Maybe< T >.TryGetValue ( out T  t)

If this Maybe has a value, the out argument is filled with that value and this method returns true, else it returns false.

Definition at line 116 of file Maybe.cs.

◆ ValueOr() [1/2]

Maybe< T > Leap.Unity.Maybe< T >.ValueOr ( Maybe< T >  maybeCustomDefault)

Returns this Maybe if it has a value, otherwise returns the argument Maybe value. Useful for overlaying multiple Maybe values. For example, if I want to overlay a "maybe override font" variable with another "maybe override font" variable, I can call: this.font = other.font.ValueOr(this.font);

Definition at line 177 of file Maybe.cs.

◆ ValueOr() [2/2]

T Leap.Unity.Maybe< T >.ValueOr ( customDefault)

If this Maybe has a value, returns the value, otherwise returns the argument custom default value.

Definition at line 162 of file Maybe.cs.

Member Data Documentation

◆ hasValue

readonly bool Leap.Unity.Maybe< T >.hasValue

Returns whether or not this Maybe contains a value.

Definition at line 69 of file Maybe.cs.

◆ None [1/2]

readonly NoneType Leap.Unity.Maybe< T >.None = new NoneType()
static

Definition at line 15 of file Maybe.cs.

◆ None [2/2]

readonly Maybe<T> Leap.Unity.Maybe< T >.None = new Maybe<T>()
static

Returns a Maybe for this type that represents no value.

Definition at line 64 of file Maybe.cs.

Property Documentation

◆ valueOrDefault

T Leap.Unity.Maybe< T >.valueOrDefault
get

Gets the value, or the type's default if it doesn't exist.

Definition at line 74 of file Maybe.cs.


The documentation for this class was generated from the following file: