Class Prelude
- Namespace
- Rascal
- Assembly
- Rascal.dll
A class containing various utility methods, a 'prelude' to the rest of the library.
public static class Prelude
- Inheritance
-
Prelude
- Inherited Members
Remarks
This class is meant to be imported statically, eg. using static Rascal.Prelude;.
Recommended to be imported globally via a global using statement.
Methods
Err<T>(Error)
Creates a result containing an error.
[Pure]
public static Result<T> Err<T>(Error error)
Parameters
errorErrorThe error to create the result from.
Returns
- Result<T>
- A class containing various utility methods, a 'prelude' to the rest of the library.
Type Parameters
TThe type of an ok value in the result.
Iterate<T>(Result<T>, Func<T, Result<T>>)
Applies a transform function onto a value until the function returns an error.
[Pure]
public static IEnumerable<T> Iterate<T>(Result<T> start, Func<T, Result<T>> transform)
Parameters
startResult<T>The starting value.
transformFunc<T, Result<T>>A function which transforms a value into either a new value or an error.
Returns
- IEnumerable<T>
A sequence of successful values produced by repeatedly applying
transformonto the previous value until an error is returned. Includesstartif it has a value, otherwise the sequence will be empty.
Type Parameters
TThe type of the value transform.
Iterate<T>(T, Func<T, Result<T>>)
Applies a transform function onto a value until the function returns an error.
[Pure]
public static IEnumerable<T> Iterate<T>(T start, Func<T, Result<T>> transform)
Parameters
startTThe starting value.
transformFunc<T, Result<T>>A function which transforms a value into either a new value or an error.
Returns
- IEnumerable<T>
A sequence of successful values produced by repeatedly applying
transformonto the previous value starting withstartuntil an error is returned.startwill always be the first element.
Type Parameters
TThe type of the value transform.
Ok<T>(T)
Creates a result containing an ok value.
[Pure]
public static Result<T> Ok<T>(T value)
Parameters
valueTThe ok value to create the result from.
Returns
- Result<T>
- A class containing various utility methods, a 'prelude' to the rest of the library.
Type Parameters
TThe type of the ok value.
TryAsync<T>(Func<Task<T>>)
Tries to execute an asynchronous function and return the result. If the function throws an exception, the exception will be returned wrapped in an ExceptionError.
[Pure]
public static Task<Result<T>> TryAsync<T>(Func<Task<T>> function)
Parameters
Returns
- Task<Result<T>>
A result containing the return value of the function or an ExceptionError containing the exception thrown by the function.
Type Parameters
TThe type the function returns.
Try<T>(Func<T>)
Tries to execute a function and return the result. If the function throws an exception, the exception will be returned wrapped in an ExceptionError.
[Pure]
public static Result<T> Try<T>(Func<T> function)
Parameters
functionFunc<T>The function to try execute.
Returns
- Result<T>
A result containing the return value of the function or an ExceptionError containing the exception thrown by the function.
Type Parameters
TThe type the function returns.