fx-sharp  0.1
A collection of functional extensions for C#.
 All Classes Namespaces Files Functions Variables Enumerator
Public Member Functions | List of all members
FxSharp.Maybe< T > Struct Template Reference

A type to describe a possibly absent val. More...

Public Member Functions

GetOrElse (T other)
 Get the stored val or the given default instead. More...
 
Maybe< TResult > Select< TResult > ([NotNull] Func< T, TResult > fn)
 Map the function fn over the wrapped val if present. Wrap the result in as well. More...
 
Maybe< T > Select_ ([NotNull] Action< T > fn)
 Map the function fn over the wrapped val if present; discard the result. More...
 
Maybe< TResult > SelectMany< TResult > ([NotNull] Func< T, Maybe< TResult >> fn)
 Map the function fn over the wrapped val if present. More...
 
Maybe< TResult > SelectMany< TInter, TResult > ([NotNull] Func< T, Maybe< TInter >> firstFn, [NotNull] Func< T, TInter, TResult > secondFn)
 Map the first function over the wrapped value and the second function over the result. If the wrapped value isn't present or the first or second functions return no value, Nothing is returned. This variant of SelectMany enables LINQ's syntactic sugar. More...
 
Maybe< T > Otherwise_ ([NotNull] Action fn)
 Call the given function, if no val is present. More...
 
TResult Match< TResult > ([NotNull] Func< TResult > nothing, [NotNull] Func< T, TResult > just)
 Map either the function just over the present val or call nothing. More...
 
Maybe< T > Match_ ([NotNull] Action nothing, [NotNull] Action< T > just)
 Map either the function just over the present val or call nothing. Ignore the result. More...
 
override string ToString ()
 

Detailed Description

A type to describe a possibly absent val.

Template Parameters
TThe type of the wrapped val.

Definition at line 100 of file Maybe.cs.

Member Function Documentation

T FxSharp.Maybe< T >.GetOrElse ( other)

Get the stored val or the given default instead.

Parameters
otherThe default val to return in case no val is stored.
Returns
Stored or given default val.
var name = TelephoneDirectory
.LookUpName("+49394965006") // LookUpName returns Maybe[string]
.GetOrElse("John Doe");

Definition at line 136 of file Maybe.cs.

TResult FxSharp.Maybe< T >.Match< TResult > ( [NotNull] Func< TResult >  nothing,
[NotNull] Func< T, TResult >  just 
)

Map either the function just over the present val or call nothing.

Template Parameters
TResultThe result type of nothing and just.
Parameters
nothingThe function to call if no val is present.
justThe function to call with a present val.
Returns
The result of the either nothing or just functions.
var name = TelephoneDirectory
.LookUpName("+49394965006") // LookUpName returns Maybe[string]
.Match(
just: name => name.ToUpper(),
nothing: () => "John Doe");

Definition at line 265 of file Maybe.cs.

Maybe<T> FxSharp.Maybe< T >.Match_ ( [NotNull] Action  nothing,
[NotNull] Action< T >  just 
)

Map either the function just over the present val or call nothing. Ignore the result.

Parameters
nothingThe function to call if no val is present.
justThe function to call with a present val.
TelephoneDirectory
.LookUpName("+49394965006") // LookUpName returns Maybe[string]
just: name => view.DisplayName(name.ToUpper()),
nothing: () => view.DisplayName("Unknown caller"));

Definition at line 287 of file Maybe.cs.

Maybe<T> FxSharp.Maybe< T >.Otherwise_ ( [NotNull] Action  fn)

Call the given function, if no val is present.

Parameters
fnA function to call if no val is present.
Returns
This instance.
TelephoneDirectory
.LookUpName("+49394965006") // LookUpName returns Maybe[string]
.Otherwise_(() => view.DisplayName("Unknown caller"));

Definition at line 238 of file Maybe.cs.

Maybe<TResult> FxSharp.Maybe< T >.Select< TResult > ( [NotNull] Func< T, TResult >  fn)

Map the function fn over the wrapped val if present. Wrap the result in as well.

Template Parameters
TResultThe type of the result of fn.
Parameters
fnA function to apply the the wrapped val.
Returns
The wrapped mapped val.
var name = TelephoneDirectory
.LookUpName("+49394965006") // LookUpName returns Maybe[string]
.Select(name => name.ToUpper());

Definition at line 155 of file Maybe.cs.

Maybe<T> FxSharp.Maybe< T >.Select_ ( [NotNull] Action< T >  fn)

Map the function fn over the wrapped val if present; discard the result.

Parameters
fnA function to apply to the wrapped val.
Returns
This.
TelephoneDirectory
.LookUpName("+49394965006") // LookUpName returns Maybe[string]
.Select_(name => view.DisplayName(name.ToUpper()));

Definition at line 175 of file Maybe.cs.

Maybe<TResult> FxSharp.Maybe< T >.SelectMany< TInter, TResult > ( [NotNull] Func< T, Maybe< TInter >>  firstFn,
[NotNull] Func< T, TInter, TResult >  secondFn 
)

Map the first function over the wrapped value and the second function over the result. If the wrapped value isn't present or the first or second functions return no value, Nothing is returned. This variant of SelectMany enables LINQ's syntactic sugar.

Template Parameters
TInterThe result tpye of the first function.
TResultThe result type of the second function.
Parameters
firstFnThe first function to apply.
secondFnThe second function to apply.
Returns
The result of the functions combined.
var caller = from name in TelephoneDirectory.LookUpName("+49394965006") // LookUpName returns Maybe[string]
from photo in SocialNetwork.LookUpPhoto(name) // LookUpPhoto returns Maybe[Image]
select new Caller(name, photo);

Definition at line 218 of file Maybe.cs.

Maybe<TResult> FxSharp.Maybe< T >.SelectMany< TResult > ( [NotNull] Func< T, Maybe< TResult >>  fn)

Map the function fn over the wrapped val if present.

Template Parameters
TResultThe type of the result of fn.
Parameters
fnA function to apply the the wrapped val which wraps the result in a Maybe.
Returns
The result of fn.

Definition at line 194 of file Maybe.cs.

override string FxSharp.Maybe< T >.ToString ( )

Returns

Definition at line 305 of file Maybe.cs.


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