ResultOrErrorᐸErrorᐳ - TheRealKoeDev/Railway-Results GitHub Wiki
NameSpace: KoeLib.Patterns.Railway.Results
public static ResultOrError<string> NetworkIsAvailable()
=> NetworkInterface.GetIsNetworkAvailable() ? ResultOrError<string>.Success() : "No network connection available.";
public static ResultOrError<string> CanPingAddress(string address, int timeout)
{
using (Ping ping = new Ping())
{
try
{
bool success = ping.Send(address, timeout).Status == IPStatus.Success;
return success ? ResultOrError<string>.Success() : "Ping failed.";
}
catch(Exception e)
{
return e.InnerException == null ? e.Message : e.InnerException.Message;
}
}
}
public static void Main()
{
string address = "www.google.com";
string message = NetworkIsAvailable()
.Bind(() => CanPingAddress(address, 1000))
.Match(() => $"{address} is accessible.", error => error);
Console.WriteLine(message);
Console.ReadLine();
}
public static implicit operator ResultOrError<TError>(TError error);
public static implicit operator Result(Result<TValue, TError> result);
In seperate class ResultOrError.
public static ResultOrError<TError> Create<TError>(bool success, Func<TError> errorFunc);
public static ResultOrError<TError> Success();
public static ResultOrError<TError> Error(TError error);
public ResultOrError<TError> OnSuccess(Action onSuccess);
public Result<TValue, TError> OnSuccess<TValue>(Func<TValue> onSuccess);
public ResultOrError<TError> OnError(Action<TError> onError);
public ResultOrError<TNewError> OnError<TNewError>(Func<TError, TNewError> onError);
public ResultOrError<TError> OnError(Action<TError> onError);
public ResultOrError<TError> Either(Action onSuccess, Action<TError> onError);
public Result<TValue, TError> Either<TValue>(Func<TValue> onSuccess, Action<TError> onError);
public ResultOrError<TNewError> Either<TNewError>(Action onSuccess, Func<TError, TNewError> onError);
public Result<TValue, TNewError> Either<TValue, TNewError>(Func<TValue> onSuccess, Func<TError, TNewError> onError);
public ResultOrError<TError> Bind(Func<ResultOrError<TError>> onSuccess);
public Result<TValue, TError> Bind<TValue>(Func<Result<TValue, TError>> onSuccess);
public TResult Bind<TResult>(Func<TResult> onSuccess, Func<TError, TResult> onError) where TResult : IResult;
public Result BindOnError(Func<TError, Result> onError);
public ResultOrError<TNewError> BindOnError<TNewError>(Func<TError, ResultOrError<TNewError>> onError);
public ResultOrError<TError> Ensure(Func<bool> condition, Func<TError> error);
public T Match<T>(Func<T> onSuccess, Func<TError, T> onError);
public ResultOrError<TError> KeepOnSuccess<T>(Func<T> onSuccess, out T kept);
public ResultOrError<TError> KeepOnError<T>(Func<TError, T> onError, out T kept);
public ResultOrError<TError> KeepEither<T>(Func<T> onSuccess, Func<TError, T> onError, out T keptValue);
public ResultOrError<TError> KeepEither<T1, T2>(Func<T1> onSuccess, Func<TError, T2> onError, out T1 keptOnSuccess, out T2 keptOnError);
public Result AsPlainResult();