Assembly Monacs.Core
Represents the details of the error in case of failed operation. To create the instances use the factory methods from the Errors class.
Properties
Contains the error severity described by ErrorLevel .
Contains optional message to describe the error details.
Property Key
Contains optional error key to identify the error.
Contains optional exception which operation ended up with. Set to None if no exception occured.
Contains optional error metadata.
Represents the severity of the error.
Contains factory methods to create instances of ErrorDetails in a more convenient way.
Methods
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 |
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 |
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 |
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 |
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 |
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 |
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
Creates a string representation of the Option`1 .
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 |
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 |
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 |
Computes the hashcode for the Option`1 instance.
Properties
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:
-
Option.GetOrDefault``1(Option{``0},``0) ,
-
Option.Map``2(Option{``0},System.Func{``0,``1}) ,
-
Option.Bind``2(Option{``0},System.Func{``0,Option{``1}}) ,
-
Option.Match``2(Option{``0},System.Func{``0,``1},System.Func{``1})
Returns true if the option has value (is Some case).
Returns true if the option has no value (is None case).
Contains the set of extensions to work with the Option`1 type.
Methods
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. |
Creates the None case instance of the Option`1 type, containing no value.
Generic parameters
Name |
Description |
T |
Desired type parameter for type. |
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 . |
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 . |
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 . |
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 . |
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 . |
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 . |
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 . |
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 . |
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 . |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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
Creates a string representation of the Result`1 .
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 |
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 |
Computes the hashcode for the Result`1 instance.
Properties
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:
-
Result.GetOrDefault``1(Result{``0},``0) ,
-
Result.Map``2(Result{``0},System.Func{``0,``1}) ,
-
Result.Bind``2(Result{``0},System.Func{``0,Result{``1}}) ,
-
Result.Match``2(Result{``0},System.Func{``0,``1},System.Func{ErrorDetails,``1})
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.
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.
Contains the set of async extensions to work with the Result`1 type.
Methods
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
Contains the set of tuple extensions to work with the Result`1 type.
Methods
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
Contains the set of extensions to work with the Result`1 type.
Methods
Method Ok
Creates the Ok case instance of the Result`1 .
Creates the Error case instance of the Result`1 type, containing error instead of value.
Parameters
Name |
Description |
error |
Details of the error. |
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 that has only one value. Used to replace void whenever some value is needed, e.g. you can return Task{Unit}.
Methods
Unit.Unit is always equal to itself. There is only one possible value of Unit.Unit .
Unit.Unit is only equal to itself.
Hash Code of Unit.Unit is always 0.
String representation of Unit.Unit is ().
Unit.Unit is always equal to itself.
Unit.Unit is always equal to itself.
Properties
The only value of Unit.Unit .