Assembly Monacs.Core

Type Monacs.Core.ErrorDetails

Represents the details of the error in case of failed operation. To create the instances use the factory methods from the Errors class.

Properties

Property Level

Contains the error severity described by ErrorLevel .

Property Message

Contains optional message to describe the error details.

Property Key

Contains optional error key to identify the error.

Property Exception

Contains optional exception which operation ended up with. Set to None if no exception occured.

Property Metadata

Contains optional error metadata.

Type Monacs.Core.ErrorLevel

Represents the severity of the error.

Type Monacs.Core.Errors

Contains factory methods to create instances of ErrorDetails in a more convenient way.

Methods

Method Trace

Creates ErrorDetails with level ErrorLevel.Trace .

Parameters
Name Description
message Optional error message
key Optional key to identify the error
exception Optional exception which caused the error
metadata Optional error metadata

Method Debug

Creates ErrorDetails with level ErrorLevel.Debug .

Parameters
Name Description
message Optional error message
key Optional key to identify the error
exception Optional exception which caused the error
metadata Optional error metadata

Method Info

Creates ErrorDetails with level ErrorLevel.Info .

Parameters
Name Description
message Optional error message
key Optional key to identify the error
exception Optional exception which caused the error
metadata Optional error metadata

Method Warn

Creates ErrorDetails with level ErrorLevel.Warn .

Parameters
Name Description
message Optional error message
key Optional key to identify the error
exception Optional exception which caused the error
metadata Optional error metadata

Method Error

Creates ErrorDetails with level ErrorLevel.Error .

Parameters
Name Description
message Optional error message
key Optional key to identify the error
exception Optional exception which caused the error
metadata Optional error metadata

Method Fatal

Creates ErrorDetails with level ErrorLevel.Fatal .

Parameters
Name Description
message Optional error message
key Optional key to identify the error
exception Optional exception which caused the error
metadata Optional error metadata

Type Monacs.Core.Option<T>

Encapsulates optional value. It is recommended to use provided extension methods and not to use properties of the Option`1 directly.

The Option can contain a value of a type T and it's called Some in such case.

If no value is encapsulated it's called None.

Generic parameters

Name Description
T Type of encapsulated value.

Methods

Method ToString

Creates a string representation of the Option`1 .

Method Equals

Compares two instances of the Option`1 . Two options are equal if both are of the same type, the same case and the underlying values are equal.

Parameters
Name Description
other Option to compare with

Method Equals

Compares Option`1 with the value of type T . Option is equal to the value of the underlying type if it's Some case and encapsulated value is equal to other value.

Parameters
Name Description
other Option to compare with

Method Equals

Compares the Option`1 with other object. Option is only equal to other option given the conditions described in Option`1.Equals(Option{`0}) .

Parameters
Name Description
obj Object to compare with

Method GetHashCode

Computes the hashcode for the Option`1 instance.

Properties

Property Value

Encapsulated value. Will be default(T) in None case.

It is not recommended to use it directly.

Use extension methods to access the value instead, like:

Property IsSome

Returns true if the option has value (is Some case).

Property IsNone

Returns true if the option has no value (is None case).

Type Monacs.Core.Option

Contains the set of extensions to work with the Option`1 type.

Methods

Method Some

Creates the Some case instance of the Option`1 type, encapsulating provided value.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to encapsulate.

Method None

Creates the None case instance of the Option`1 type, containing no value.

Generic parameters
Name Description
T Desired type parameter for type.

Method OfObject

Converts the value of class T to the Option`1 type. If the value is null, the None case is yielded. Otherwise Some case with provided value is returned.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .

Method ToOption

Converts the value of class T to the Option`1 type. If the value is null, the None case is yielded. Otherwise Some case with provided value is returned.

Remarks: Extension method variant of Option.OfObject``1(``0)

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .

Method OfNullable

Converts the value of System.Nullable`1 to the Option`1 type. If the value is null, the None case is yielded. Otherwise Some case with provided value is returned.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .

Method ToOption

Converts the value of System.Nullable`1 to the Option`1 type. If the value is null, the None case is yielded. Otherwise Some case with provided value is returned.

Remarks: Extension method variant of Option.OfNullable``1(System.Nullable{``0})

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .

Method ToNullable

Converts the value of Option`1 to the System.Nullable`1 type. If the option is the None case, null is yielded. Otherwise encapsulated value is returned.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .

Method OfString

Converts the string value to the Option`1 type. If the value is null or empty string, the None case is yielded. Otherwise Some case with provided value is returned.

Parameters
Name Description
value The value to convert to .

Method ToOption

Converts the string value to the Option{string} type. If the value is null or empty string, the None case is yielded. Otherwise Some case with provided value is returned.

Remarks: Extension method variant of Option.OfString(System.String)

Parameters
Name Description
value The value to convert to .

Method OfResult

Converts the value of Result`1 to the Option`1 type. If the value is the Error case, the None case is yielded. Otherwise Some case with encapsulated value is returned.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .

Method ToOption

Converts the value of Result`1 to the Option`1 type. If the value is the Error case, the None case is yielded. Otherwise Some case with encapsulated value is returned.

Remarks: Extension method variant of Option.OfResult``1(Result{``0})

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .

Method TryGetOption

Tries to get the element with the given key from the dictionary . If the value is found, returns Some case of the Option`1 type with the value from the dictionary. Otherwise returns None case of the Option`1 type.

Generic parameters
Name Description
TKey Type of the key in the dictionary.
TValue Type of the value in the dictionary.
Parameters
Name Description
dictionary The dictionary to search in.
key The key to look for.

Method TryGetOption

Tries to get the elements with the given key from the lookup . If any value is found, returns Some case of the Option`1 type with the values from the lookup. Otherwise returns None case of the Option`1 type.

Generic parameters
Name Description
TKey Type of the key in the lookup.
TValue Type of the value in the lookup.
Parameters
Name Description
lookup The lookup to search in.
key The key to look for.

Method Match

Does the pattern matching on the Option`1 type. If the option is Some, calls some function with the value from the option as a parameter and returns its result. Otherwise calls none function and returns its result.

Generic parameters
Name Description
TIn Type of the value in the option.
TOut Type of the returned value.
Parameters
Name Description
option The option to match on.
some Function called for the Some case.
none Function called for the None case.

Method MatchTo

Does the pattern matching on the Option`1 type. If the option is Some, returns some value. Otherwise returns none value.

Generic parameters
Name Description
TIn Type of the value in the option.
TOut Type of the returned value.
Parameters
Name Description
option The option to match on.
some Value returned for the Some case.
none Value returned for the None case.

Method Bind

Transforms the option into another Option`1 using the binder function. If the input option is Some, returns the value of the binder call (which is TOut option). Otherwise returns None case of the TOut option.

Generic parameters
Name Description
TIn Type of the value in the input option.
TOut Type of the value in the returned option.
Parameters
Name Description
option The option to bind with.
binder Function called with the input option value if it's Some case.

Method Map

Maps the value of the option into another Option`1 using the mapper function. If the input option is Some, returns the Some case with the value of the mapper call (which is TOut ). Otherwise returns None case of the TOut option.

Generic parameters
Name Description
TIn Type of the value in the input option.
TOut Type of the value in the returned option.
Parameters
Name Description
option The option to map on.
mapper Function called with the input option value if it's Some case.

Method GetOrDefault

Gets the value of the option if it's Some case. If the option is None case returns value specified by the whenNone parameter; if the parameter is not set returns the default value of the type T .

Generic parameters
Name Description
T Type of the value in the option.
Parameters
Name Description
option The option to get a value from.
whenNone Value to return if the option is the None case.

Method GetOrDefault

Gets the value from the option using the getter function if it's Some case. If the option is None case returns value specified by the whenNone parameter; if the parameter is not set returns the default value of the type TOut .

Remarks: Effectively the combination of Option.Map``2(Option{``0},System.Func{``0,``1}) and Option.GetOrDefault``1(Option{``0},``0) calls.

Generic parameters
Name Description
TIn Type of the value in the option.
TOut Type of the return value.
Parameters
Name Description
option The option to get a value from.
getter Function used to get the value if the option is the Some case.
whenNone Value to return if the option is the None case.

Method Do

Performs the action with the value of the option if it's Some case. If the option is None case nothing happens. In both cases unmodified option is returned.

Generic parameters
Name Description
T Type of the value in the option.
Parameters
Name Description
option The option to check for a value.
action Function executed if the option is Some case.

Method DoWhenNone

Performs the action if the option is None case. If the option is Some case nothing happens. In both cases unmodified option is returned.

Generic parameters
Name Description
T Type of the value in the option.
Parameters
Name Description
option The option to check for a value.
action Function executed if the option is None case.

Method Choose

Returns the collection of values of elements from the Option`1 collection that are Some case (so contain some value).

Generic parameters
Name Description
T Type of the value in the option.
Parameters
Name Description
items Collection to filter out and map.

Method Sequence

If all elements in the input collection are Some case, returns the Some of the collection of underlying values. Otherwise returns None.

Generic parameters
Name Description
T Type of the value in the option.
Parameters
Name Description
items Collection to check and map.

Method TryFind

Tries to find the first element of the items collection matching the predicate . If element is found, returns Some with the value of that element. Otherwise returns None.

Generic parameters
Name Description
T Type of the value in the collection and returned option.
Parameters
Name Description
items Collection to search in.
predicate Function that checks if given element matches desired condition.

Method TryFirst

Tries to get the the element in the items collection. If element is found, returns Some with the value of that element. Otherwise returns None.

Generic parameters
Name Description
T Type of the value in the collection and the returned option.
Parameters
Name Description
items Collection to search in.

Method TryElementAt

Tries to get the element of the items collection at the posision given by the index parameter. If element is found, returns Some with the value of that element. Otherwise returns None.

Generic parameters
Name Description
T Type of the value in the collection and returned option.
Parameters
Name Description
items Collection to search in.
index Position at which to look for an element.

Type Monacs.Core.Result<T>

Represents the result of the operation that may succeed or fail. It is recommended to use provided extension methods and not to use properties of the Result`1 directly.

If the operation succeeded it will contain a value of a type T and it's called Ok in such case.

If the operation failed it will contain error information of type ErrorDetails and it's called Error.

Generic parameters

Name Description
T Expected return value type.

Methods

Method ToString

Creates a string representation of the Result`1 .

Method Equals

Compares two instances of the Result`1 . Two results are equal if both are of the same type, the same case and the underlying values (of errors) are equal.

Parameters
Name Description
other Result to compare with

Method Equals

Compares the Result`1 with other object. Result is only equal to other result given the conditions described in Result`1.Equals(Result{`0}) .

Parameters
Name Description
obj Object to compare with

Method GetHashCode

Computes the hashcode for the Result`1 instance.

Properties

Property Value

Contains the computed value of the operation if it ends successfully.

It is not recommended to use it directly.

Use extension methods to access the value instead, like:

Property Error

Contains error details when operation ended up with failure.

It is not recommended to use it directly.

Use extension methods to access the value instead, like:

Property IsOk

Indicates that the Result is on the success path (Ok case). You should expect the output in the Result`1.Value field.

Property IsError

Indicates that the result is on the failure path (Error case). You should expect error in Result`1.Error field and no value in the Result`1.Value field.

Type Monacs.Core.AsyncResult

Contains the set of async extensions to work with the Result`1 type.

Methods

Method BindAsync

Transforms the result into another Result`1 using the binder function. If the input result is Ok, returns the value of the binder call (which is Result`1 of TOut ). Otherwise returns Error case of the Result of TOut .

Generic parameters
Name Description
TIn Type of the value in the input result.
TOut Type of the value in the returned result.
Parameters
Name Description
result The result to bind with.
binder Function called with the input result value if it's Ok case.

Method BindAsync

Transforms the result into another Result`1 using the binder function. If the input result is Ok, returns the value of the binder call (which is Result`1 of TOut ). Otherwise returns Error case of the Result of TOut .

Generic parameters
Name Description
TIn Type of the value in the input result.
TOut Type of the value in the returned result.
Parameters
Name Description
result The result to bind with.
binder Function called with the input result value if it's Ok case.

Method BindAsync

Transforms the result into another Result`1 using the binder function. If the input result is Ok, returns the value of the binder call (which is Result`1 of TOut ). Otherwise returns Error case of the Result of TOut .

Generic parameters
Name Description
TIn Type of the value in the input result.
TOut Type of the value in the returned result.
Parameters
Name Description
result The result to bind with.
binder Function called with the input result value if it's Ok case.

Method MapAsync

Maps the value of the result into another Result`1 using the mapper function. If the input result is Ok, returns the Ok case with the value of the mapper call (which is TOut ). Otherwise returns Error case of the Result of TOut .

Generic parameters
Name Description
TIn Type of the value in the input result.
TOut Type of the value in the returned result.
Parameters
Name Description
result The result to map on.
mapper Function called with the input result value if it's Ok case.

Method MapAsync

Maps the value of the result into another Result`1 using the mapper function. If the input result is Ok, returns the Ok case with the value of the mapper call (which is TOut ). Otherwise returns Error case of the Result of TOut .

Generic parameters
Name Description
TIn Type of the value in the input result.
TOut Type of the value in the returned result.
Parameters
Name Description
result The result to map on.
mapper Function called with the input result value if it's Ok case.

Method MapAsync

Maps the value of the result into another Result`1 using the mapper function. If the input result is Ok, returns the Ok case with the value of the mapper call (which is TOut ). Otherwise returns Error case of the Result of TOut .

Generic parameters
Name Description
TIn Type of the value in the input result.
TOut Type of the value in the returned result.
Parameters
Name Description
result The result to map on.
mapper Function called with the input result value if it's Ok case.

Method MatchAsync

Does the pattern matching on the Result`1 type. If the result is Ok, calls ok function with the value from the result as a parameter and returns its result. Otherwise calls error function and returns its result.

Generic parameters
Name Description
TIn Type of the value in the result.
TOut Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Function called for the Ok case.
error Function called for the Error case.

Method MatchAsync

Does the pattern matching on the Result`1 type. If the result is Ok, calls ok function with the value from the result as a parameter and returns its result. Otherwise calls error function and returns its result.

Generic parameters
Name Description
TIn Type of the value in the result.
TOut Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Function called for the Ok case.
error Function called for the Error case.

Method MatchAsync

Does the pattern matching on the Result`1 type. If the result is Ok, calls ok function with the value from the result as a parameter and returns its result. Otherwise calls error function and returns its result.

Generic parameters
Name Description
TIn Type of the value in the result.
TOut Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Function called for the Ok case.
error Function called for the Error case.

Method MatchAsync

Does the pattern matching on the Result`1 type. If the result is Ok, calls ok function with the value from the result as a parameter and returns its result. Otherwise calls error function and returns its result.

Generic parameters
Name Description
TIn Type of the value in the result.
TOut Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Function called for the Ok case.
error Function called for the Error case.

Method MatchAsync

Does the pattern matching on the Result`1 type. If the result is Ok, calls ok function with the value from the result as a parameter and returns its result. Otherwise calls error function and returns its result.

Generic parameters
Name Description
TIn Type of the value in the result.
TOut Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Function called for the Ok case.
error Function called for the Error case.

Method MatchAsync

Does the pattern matching on the Result`1 type. If the result is Ok, calls ok function with the value from the result as a parameter and returns its result. Otherwise calls error function and returns its result.

Generic parameters
Name Description
TIn Type of the value in the result.
TOut Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Function called for the Ok case.
error Function called for the Error case.

Method MatchAsync

Does the pattern matching on the Result`1 type. If the result is Ok, calls ok function with the value from the result as a parameter and returns its result. Otherwise calls error function and returns its result.

Generic parameters
Name Description
TIn Type of the value in the result.
TOut Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Function called for the Ok case.
error Function called for the Error case.

Method IgnoreAsync

Rejects the value of the Result`1 and returns Result`1 instead. If the input Result`1 is Error then the error details are preserved.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
result The result of which the value should be ignored.

Method DoAsync

Performs the action with the value of the result if it's Ok case. If the result is Error case nothing happens. In both cases unmodified result is returned.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
result The result to check for a value.
action Function executed if the result is Ok case.

Method DoAsync

Performs the action with the value of the result if it's Ok case. If the result is Error case nothing happens. In both cases unmodified result is returned.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
result The result to check for a value.
action Function executed if the result is Ok case.

Method DoAsync

Performs the action with the value of the result if it's Ok case. If the result is Error case nothing happens. In both cases unmodified result is returned.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
result The result to check for a value.
action Function executed if the result is Ok case.

Method DoWhenErrorAsync

Performs the action if the result is Error case. If the result is Ok case nothing happens. In both cases unmodified result is returned.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
result The result to check for a value.
action Function executed if the result is Error case.

Method DoWhenErrorAsync

Performs the action if the result is Error case. If the result is Ok case nothing happens. In both cases unmodified result is returned.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
result The result to check for a value.
action Function executed if the result is Error case.

Method DoWhenErrorAsync

Performs the action if the result is Error case. If the result is Ok case nothing happens. In both cases unmodified result is returned.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
result The result to check for a value.
action Function executed if the result is Error case.

Method FlipAsync

Transforms Result`1 with async value inside to System.Threading.Tasks.Task`1 of the result, preserving original result's state and value.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
result Result to take the value from.

Method TryCatchAsync

Tries to execute func . If the execution completes without exception, returns Ok with the function result. Otherwise returns Error with details generated by errorHandler based on the thrown exception.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
func Function to execute.
errorHandler Function that generates error details in case of exception.

Method TryCatchAsync

Tries to execute func with the value from the result as an input. If the execution completes without exception, returns Ok with the function result. Otherwise returns Error with details generated by errorHandler based on the thrown exception. If the result is Error function is not executed and the Error is returned.

Generic parameters
Name Description
TIn Type of the value in the input result.
TOut Type of the value in the output result.
Parameters
Name Description
result Result to take the value from.
func Function to execute.
errorHandler Function that generates error details in case of exception.

Type Monacs.Core.Result

Contains the set of extensions to work with the Result`1 type.

Methods

Method Ok

Creates the Ok case instance of the Result`1 type, encapsulating provided value.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to encapsulate.

Method Error

Creates the Error case instance of the Result`1 type, containing error instead of value.

Generic parameters
Name Description
T Desired type parameter for type.
Parameters
Name Description
error Details of the error.

Method OfObject

Converts the value of class T to the Result`1 type. If the value is null, the Error case is yielded. Otherwise Ok case with provided value is returned.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
error Details of the error if the value is null.

Method OfObject

Converts the value of class T to the Result`1 type. If the value is null, the Error case is yielded. Otherwise Ok case with provided value is returned.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
errorFunc Function yielding details of the error if the value is null.

Method ToResult

Converts the value of class T to the Result`1 type. If the value is null, the Error case is yielded. Otherwise Ok case with provided value is returned.

Remarks: Extension method variant of Result.OfObject``1(``0,ErrorDetails)

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
error Details of the error if the value is null.

Method ToResult

Converts the value of class T to the Result`1 type. If the value is null, the Error case is yielded. Otherwise Ok case with provided value is returned.

Remarks: Extension method variant of Result.OfObject``1(``0,System.Func{ErrorDetails})

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
errorFunc Function yielding details of the error if the value is null.

Method OfNullable

Converts the value of System.Nullable`1 to the Result`1 type. If the value is null, the Error case is yielded. Otherwise Ok case with provided value is returned.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
error Details of the error if the value is null.

Method OfNullable

Converts the value of System.Nullable`1 to the Result`1 type. If the value is null, the Error case is yielded. Otherwise Ok case with provided value is returned.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
errorFunc Function yielding details of the error if the value is null.

Method ToResult

Converts the value of System.Nullable`1 to the Result`1 type. If the value is null, the Error case is yielded. Otherwise Ok case with provided value is returned.

Remarks: Extension method variant of Result.OfNullable``1(System.Nullable{``0},ErrorDetails)

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
error Details of the error if the value is null.

Method ToResult

Converts the value of System.Nullable`1 to the Result`1 type. If the value is null, the Error case is yielded. Otherwise Ok case with provided value is returned.

Remarks: Extension method variant of Result.OfNullable``1(System.Nullable{``0},System.Func{ErrorDetails})

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
errorFunc Function yielding details of the error if the value is null.

Method OfString

Converts the string value to the Result`1 type. If the value is null or empty string, the Error case is yielded. Otherwise Ok case with provided value is returned.

Parameters
Name Description
value The value to convert to .
error Details of the error if the value is null or empty.

Method OfString

Converts the string value to the Result`1 type. If the value is null or empty string, the Error case is yielded. Otherwise Ok case with provided value is returned.

Parameters
Name Description
value The value to convert to .
errorFunc Function yielding details of the error if the value is null or empty.

Method ToResult

Converts the string value to the Result`1 type. If the value is null or empty string, the Error case is yielded. Otherwise Ok case with provided value is returned.

Remarks: Extension method variant of Result.OfString(System.String,ErrorDetails)

Parameters
Name Description
value The value to convert to .
error Details of the error if the value is null or empty.

Method ToResult

Converts the string value to the Result`1 type. If the value is null or empty string, the Error case is yielded. Otherwise Ok case with provided value is returned.

Remarks: Extension method variant of Result.OfString(System.String,System.Func{ErrorDetails})

Parameters
Name Description
value The value to convert to .
errorFunc Function yielding details of the error if the value is null or empty.

Method OfOption

Converts the value of Option`1 to the Result`1 type. If the value is None case, the Error case is yielded. Otherwise Ok case with provided value is returned.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
error Details of the error if the value is None.

Method OfOption

Converts the value of Option`1 to the Result`1 type. If the value is None case, the Error case is yielded. Otherwise Ok case with provided value is returned.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
errorFunc Function yielding details of the error if the value is None.

Method ToResult

Converts the value of Option`1 to the Result`1 type. If the value is None case, the Error case is yielded. Otherwise Ok case with provided value is returned.

Remarks: Extension method variant of Result.OfOption``1(Option{``0},ErrorDetails)

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
error Details of the error if the value is None.

Method ToResult

Converts the value of Option`1 to the Result`1 type. If the value is None case, the Error case is yielded. Otherwise Ok case with provided value is returned.

Remarks: Extension method variant of Result.OfOption``1(Option{``0},System.Func{ErrorDetails})

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
value The value to convert to .
errorFunc Function yielding details of the error if the value is None.

Method TryGetResult

Tries to get the element with the given key from the dictionary . If the value is found, returns Ok case of the Result`1 type with the value from the dictionary. Otherwise returns Error case of the Result`1 type.

Generic parameters
Name Description
TKey Type of the key in the dictionary.
TValue Type of the value in the dictionary.
Parameters
Name Description
dictionary The dictionary to search in.
key The key to look for.
error Details of the error if the key is not found.

Method TryGetResult

Tries to get the element with the given key from the dictionary . If the value is found, returns Ok case of the Result`1 type with the value from the dictionary. Otherwise returns Error case of the Result`1 type.

Generic parameters
Name Description
TKey Type of the key in the dictionary.
TValue Type of the value in the dictionary.
Parameters
Name Description
dictionary The dictionary to search in.
key The key to look for.
errorFunc Function yielding details of the error if the key is not found.

Method TryGetResult

Tries to get the elements with the given key from the lookup . If any value is found, returns Ok case of the Result`1 type with the values from the lookup. Otherwise returns Error case of the Result`1 type.

Generic parameters
Name Description
TKey Type of the key in the lookup.
TValue Type of the value in the lookup.
Parameters
Name Description
lookup The lookup to search in.
key The key to look for.
error Details of the error if the key is not found.

Method TryGetResult

Tries to get the elements with the given key from the lookup . If any value is found, returns Ok case of the Result`1 type with the values from the lookup. Otherwise returns Error case of the Result`1 type.

Generic parameters
Name Description
TKey Type of the key in the lookup.
TValue Type of the value in the lookup.
Parameters
Name Description
lookup The lookup to search in.
key The key to look for.
errorFunc Function yielding details of the error if the key is not found.

Method Match

Does the pattern matching on the Result`1 type. If the result is Ok, calls ok function with the value from the result as a parameter and returns its result. Otherwise calls error function and returns its result.

Generic parameters
Name Description
TIn Type of the value in the result.
TOut Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Function called for the Ok case.
error Function called for the Error case.

Method MatchTo

Does the pattern matching on the Result`1 type. If the result is Ok, returns ok value. Otherwise returns error value.

Generic parameters
Name Description
TIn Type of the value in the result.
TOut Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Value returned for the Ok case.
error Value returned for the Error case.

Method Bind

Transforms the result into another Result`1 using the binder function. If the input result is Ok, returns the value of the binder call (which is Result`1 of TOut ). Otherwise returns Error case of the Result of TOut .

Generic parameters
Name Description
TIn Type of the value in the input result.
TOut Type of the value in the returned result.
Parameters
Name Description
result The result to bind with.
binder Function called with the input result value if it's Ok case.

Method Map

Maps the value of the result into another Result`1 using the mapper function. If the input result is Ok, returns the Ok case with the value of the mapper call (which is TOut ). Otherwise returns Error case of the Result of TOut .

Generic parameters
Name Description
TIn Type of the value in the input result.
TOut Type of the value in the returned result.
Parameters
Name Description
result The result to map on.
mapper Function called with the input result value if it's Ok case.

Method GetOrDefault

Gets the value of the result if it's Ok case. If the result is Error case returns value specified by the whenError parameter; if the parameter is not set returns the default value of the type T .

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
result The result to get a value from.
whenError Value to return if the result is the Error case.

Method GetOrDefault

Gets the value from the result using the getter function if it's Ok case. If the result is Error case returns value specified by the whenError parameter; if the parameter is not set returns the default value of the type TOut .

Remarks: Effectively the combination of Result.Map``2(Result{``0},System.Func{``0,``1}) and Result.GetOrDefault``1(Result{``0},``0) calls.

Generic parameters
Name Description
TIn Type of the value in the result.
TOut Type of the return value.
Parameters
Name Description
result The result to get a value from.
getter Function used to get the value if the result is the Ok case.
whenError Value to return if the result is the Error case.

Method Do

Performs the action with the value of the result if it's Ok case. If the result is Error case nothing happens. In both cases unmodified result is returned.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
result The result to check for a value.
action Function executed if the result is Ok case.

Method DoWhenError

Performs the action if the result is Error case. If the result is Ok case nothing happens. In both cases unmodified result is returned.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
result The result to check for a value.
action Function executed if the result is Error case.

Method Choose

Returns the collection of values of elements from the Result`1 collection that are Ok case.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
items Collection to filter out and map.

Method ChooseErrors

Returns the collection of values of elements from the Result`1 collection that are Error case.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
items Collection to filter out and map.

Method Sequence

If all elements in the input collection are Ok case, returns the Ok of the collection of underlying values. Otherwise returns Error from the first element.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
items Collection to check and map.

Method TryCatch

Tries to execute func . If the execution completes without exception, returns Ok with the function result. Otherwise returns Error with details generated by errorHandler based on the thrown exception.

Generic parameters
Name Description
T Type of the value in the result.
Parameters
Name Description
func Function to execute.
errorHandler Function that generates error details in case of exception.

Method TryCatch

Tries to execute func with the value from the result as an input. If the execution completes without exception, returns Ok with the function result. Otherwise returns Error with details generated by errorHandler based on the thrown exception. If the result is Error function is not executed and the Error is returned.

Generic parameters
Name Description
TIn Type of the value in the input result.
TOut Type of the value in the output result.
Parameters
Name Description
result Result to take the value from.
func Function to execute.
errorHandler Function that generates error details in case of exception.

Type Monacs.Core.TupleResult

Contains the set of tuple extensions to work with the Result`1 type.

Methods

Method Map2

Maps the value of the result into another Result`1 using the mapper function.

If the input result is Ok, returns the Ok case with the value of the mapper call (which is TResult ). Otherwise returns Error case of the Result of TResult .

Generic parameters
Name Description
TFst Type of first value in input result.
TSnd Type of second value in input result.
TResult Type of the value in the returned result.
Parameters
Name Description
result The result to map on.
mapper Function called with the input result value if it's Ok case.

Method Map3

Maps the value of the result into another Result`1 using the mapper function.

If the input result is Ok, returns the Ok case with the value of the mapper call (which is TResult ). Otherwise returns Error case of the Result of TResult .

Generic parameters
Name Description
TFst Type of first value in input result.
TSnd Type of second value in input result.
TTrd Type of third value in input result.
TResult Type of the value in the returned result.
Parameters
Name Description
result The result to map on.
mapper Function called with the input result value if it's Ok case.

Method Bind2

Applies railway pattern and binds two functions.

If the result of the previous function is on the success path, the received result is taken as an argument and the next function is invoked.

If the result of the previous function is on the failure path, the new error is created to match generic result type, but the error details remain the same.

Returns: Result of the second function or error received from the first function.

Generic parameters
Name Description
TFst Type of the first output tuple value received from previous function.
TSnd Type of the second output tuple value received from previous function.
TResult Type of the output value.
Parameters
Name Description
result Output of previous function
binder Passes the output of first function to the next one.

Method Bind3

Applies railway pattern and binds two functions.

If the result of the previous function is on the success path, the received result is taken as an argument and the next function is invoked.

If the result of the previous function is on the failure path, the new error is created to match generic result type, but the error details remain the same.

Returns: Result of the second function or error received from the first function.

Generic parameters
Name Description
TFst Type of the first output tuple value received from previous function.
TSnd Type of the second output tuple value received from previous function.
TTrd Type of the second output tuple value received from previous function.
TResult Type of the output value.
Parameters
Name Description
result Output of previous function
binder Passes the output of first function to the next one.

Method Match2

Does the pattern matching on the Result`1 type. If the result is Ok, calls ok function with the value from the result as a parameter and returns its result. Otherwise calls error function and returns its result.

Generic parameters
Name Description
TFst Type of the first tuple value in the result.
TSnd Type of the second tuple value in the result.
TResult Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Function called for the Ok case.
error Function called for the Error case.

Method Match3

Does the pattern matching on the Result`1 type. If the result is Ok, calls ok function with the value from the result as a parameter and returns its result. Otherwise calls error function and returns its result.

Generic parameters
Name Description
TFst Type of the first tuple value in the result.
TSnd Type of the second tuple value in the result.
TTrd Type of the third tuple value in the result.
TResult Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Function called for the Ok case.
error Function called for the Error case.

Method MatchTo2

Does the pattern matching on the Result`1 type. If the result is Ok, returns ok value. Otherwise returns error value.

Generic parameters
Name Description
TFst Type of the first tuple value in the result.
TSnd Type of the second tuple value in the result.
TResult Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Value returned for the Ok case.
error Value returned for the Error case.

Method MatchTo3

Does the pattern matching on the Result`1 type. If the result is Ok, returns ok value. Otherwise returns error value.

Generic parameters
Name Description
TFst Type of the first tuple value in the result.
TSnd Type of the second tuple value in the result.
TTrd Type of the third tuple value in the result.
TResult Type of the returned value.
Parameters
Name Description
result The result to match on.
ok Value returned for the Ok case.
error Value returned for the Error case.

Method Do2

Performs action if the given result is on the succesful path. The action takes given result as an argument.

Returns: Result passed to the method as an argument.

Generic parameters
Name Description
TFst Type of first tuple result value.
TSnd Type of second tuple result value.
Parameters
Name Description
result Given result.
action Action to perform.

Method Do3

Performs action if the given result is on the succesful path. The action takes given result as an argument.

Returns: Result passed to the method as an argument.

Generic parameters
Name Description
TFst Type of first tuple result value.
TSnd Type of second tuple result value.
TTrd Type of third tuple result value.
Parameters
Name Description
result Given result.
action Action to perform.

Method TryCatch2

Invokes function in try/catch block and returns its result. If any System.Exception is raised during execution, error handler is invoked and error details are returned.

Returns: Result`1 of invoked function in try block or ErrorDetails if any exception occurs.

Generic parameters
Name Description
TFst Type of first tuple result value.
TSnd Type of second tuple result value.
TResult Type of value returned by invoked function.
Parameters
Name Description
result Result to take the value from.
tryFunc The function to be invoked in 'try' block.
errorHandler Handler invoked in 'catch' block on any raised exception.

Method TryCatch3

Invokes function in try/catch block and returns its result. If any System.Exception is raised during execution, error handler is invoked and error details are returned.

Returns: Result`1 of invoked function in try block or ErrorDetails if any exception occurs.

Generic parameters
Name Description
TFst Type of first tuple result value.
TSnd Type of second tuple result value.
TTrd Type of third tuple result value.
TResult Type of value returned by invoked function.
Parameters
Name Description
result Result to take the value from.
tryFunc The function to be invoked in 'try' block.
errorHandler Handler invoked in 'catch' block on any raised exception.

Type Monacs.Core.UnitResult

Contains the set of extensions to work with the Result`1 type.

Methods

Method Ok

Creates the Ok case instance of the Result`1 .

Method Error

Creates the Error case instance of the Result`1 type, containing error instead of value.

Parameters
Name Description
error Details of the error.

Method Ignore

Rejects the value of the Result`1 and returns Result`1 instead. If the input Result`1 is Error then the error details are preserved.

Generic parameters
Name Description
T Type of the encapsulated value.
Parameters
Name Description
result The result of which the value should be ignored.

Type Monacs.Core.Unit.Unit

Type that has only one value. Used to replace void whenever some value is needed, e.g. you can return Task{Unit}.

Methods

Method Equals

Unit.Unit is always equal to itself. There is only one possible value of Unit.Unit .

Method Equals

Unit.Unit is only equal to itself.

Method GetHashCode

Hash Code of Unit.Unit is always 0.

Method ToString

String representation of Unit.Unit is ().

Method op_Equality

Unit.Unit is always equal to itself.

Method op_Inequality

Unit.Unit is always equal to itself.

Properties

Property Default

The only value of Unit.Unit .