Result - TheRealKoeDev/Railway-Results GitHub Wiki
NameSpace: KoeLib.Patterns.Railway.Results
public static Result NetworkIsAvailable() => NetworkInterface.GetIsNetworkAvailable();
public static Result CanPingAddress(string address, int timeout)
{
using (Ping ping = new Ping())
{
try
{
return ping.Send(address, timeout).Status == IPStatus.Success;
}
catch
{
return false;
}
}
}
public static void Main()
{
string address = "www.google.com";
string status = NetworkIsAvailable()
.Bind(() => CanPingAddress(address, 1000))
.Match(() => "accessible", () => "not accessible");
Console.WriteLine($"{address} is {status}.");
Console.ReadLine();
}
public static implicit operator Result(bool success);
public static Result Create(bool success);
public static Result<TValue> Create<TValue>(bool success, Func<TValue> valueFunc);
public static Result<TValue, TError> Create<TValue, TError>(bool success, Func<TValue> valueFunc, Func<TError> errorFunc);
public static Result Success();
public static Result Error();
public static Result Combine(params Result[] results);
public static TryCatchResult<T> Try<T>(Func<T> func);
public Result OnSuccess(Action onSuccess);
public Result<TValue> OnSuccess<TValue>(Func<TValue> onSuccess);
public Result OnError(Action onError);
public ResultOrError<TError> OnError<TError>(Func<TError> onError);
public Result FixOnError(Action onError);
public Result Either(Action onSuccess, Action onError);
public Result<TValue> Either<TValue>(Func<TValue> onSuccess, Action onError);
public ResultOrError<TError> Either<TError>(Action onSuccess, Func<TError> onError);
public Result<TValue,TError> Either<TValue,TError>(Func<TValue> onSuccess, Func<TError> onError);
public Result Bind(Func<Result> onSuccess);
public Result<TValue> Bind<TValue>(Func<Result<TValue>> onSuccess);
public TResult Bind<TResult>(Func<TResult> onSuccess, Func<TResult> onError) where TResult: IResult;
public Result BindOnError(Func<Result> onError);
public ResultOrError<TError> BindOnError<TError>(Func<ResultOrError<TError>> onError);
public Result Ensure(Func<bool> condition);
public T Match<T>(Func<T> onSuccess, Func<T> onError);
public Result KeepOnSuccess<T>(Func<T> onSuccess, out T kept);
public Result KeepOnError<T>(Func<T> onError, out T kept);
public Result KeepEither<T>(Func<T> onSuccess, Func<T> onError, out T keptValue);
public Result KeepEither<T1, T2>(Func<T1> onSuccess, Func<T2> onError, out T1 keptOnSuccess, out T2 keptOnError);