using CSharpFunctionalExtensions;
static void Main(string[] args)
var result = ProcessData("valid input").Bind(ValidateData).Bind(SaveData);
success => Console.WriteLine($"Success: {success}"),
error => Console.WriteLine($"Error: {error}"));
static Result<string, ApplicationError> ProcessData(string input)
if (string.IsNullOrEmpty(input))
return Result.Failure<string, ApplicationError>(new ApplicationError("Input cannot be empty"));
return Result.Success<string, ApplicationError>(input.ToUpper());
static Result<string, ApplicationError> ValidateData(string data)
return Result.Failure<string, ApplicationError>(new ApplicationError("Data is too short"));
return Result.Success<string, ApplicationError>(data);
static Result<string, ApplicationError> SaveData(string data)
return Result.Failure<string, ApplicationError>(new ApplicationError("Failed to save data"));
return Result.Success<string, ApplicationError>("Data saved successfully");
public class ApplicationError
public string Message { get; }
public ApplicationError(string message)
public override string ToString() => Message;