ResultᐸValueᐳ - TheRealKoeDev/Railway-Results GitHub Wiki
NameSpace: KoeLib.Patterns.Railway.Results
public static Result<string> GetPageContent(string address)
{
try
{
using (WebClient client = new WebClient())
{
return client.DownloadString(address);
}
}
catch
{
return Result<string>.Error();
}
}
public static Result<string> StoreContent(string content, string filename)
{
try
{
DirectoryInfo directory = Directory.CreateDirectory(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "example-downloads")));
File.WriteAllText(directory.FullName + "\\" + Path.GetFileName(filename), content);
return "Success";
}
catch
{
return Result<string>.Error();
}
}
public static void Main()
{
string address = "https://www.google.com";
string status = GetPageContent(address)
.Bind(content => StoreContent(content, address + ".html"))
.Match(message => message, () => "Error");
Console.WriteLine($"{address} download and storage ended with status: {status}");
Console.ReadLine();
}
public static implicit operator Result<TValue>(TValue value);
public static implicit operator Result(Result<TValue> result);
public static Result<TValue> Success(TValue value);
public static Result<TValue> Error();
public Result<TValue> OnSuccess(Action<TValue> onSuccess);
public Result<TNewValue> OnSuccess<TNewValue>(Func<TValue, TNewValue> onSuccess);
public Result<TValue> OnError(Action onError);
public Result<TValue, TError> OnError<TError>(Func<TError> onError);
public Result<TValue> FixOnError(Func<TValue> onError);
public Result<TValue> Either(Action<TValue> onSuccess, Action onError);
public Result<TNewValue> Either<TNewValue>(Func<TValue, TNewValue> onSuccess, Action onError);
public Result<TValue, TError> Either<TError>(Action<TValue> onSuccess, Func<TError> onError);
public Result<TNewValue, TError> Either<TNewValue, TError>(Func<TValue, TNewValue> onSuccess, Func<TError> onError);
public Result Bind(Func<TValue, Result> onSuccess);
public Result<TNewValue> Bind<TNewValue>(Func<TValue, Result<TNewValue>> onSuccess);
public TResult Bind<TResult>(Func<TValue, TResult> onSuccess, Func<TResult> onError) where TResult: IResult;
public Result<TValue> BindOnError(Func<Result<TValue>> onError);
public Result<TValue, TError> BindOnError<TError>(Func<Result<TValue, TError>> onError);
public Result<TValue> Ensure(Func<TValue, bool> condition);
public T Match<T>(Func<TValue, T> onSuccess, Func<T> onError);
public Result<TValue> KeepOnSuccess<T>(Func<TValue, T> onSuccess, out T kept);
public Result<TValue> KeepOnError<T>(Func<T> onError, out T kept);
public Result<TValue> KeepEither<T>(Func<TValue, T> onSuccess, Func<T> onError, out T keptValue);
public Result<TValue> KeepEither<T1, T2>(Func<TValue, T1> onSuccess, Func<T2> onError, out T1 keptOnSuccess, out T2 keptOnError);
public Result AsPlainResult();