Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend FluentResults with Result<TValue, TRequest> #220

Open
martin-hirsch opened this issue Aug 22, 2024 · 0 comments
Open

Extend FluentResults with Result<TValue, TRequest> #220

martin-hirsch opened this issue Aug 22, 2024 · 0 comments

Comments

@martin-hirsch
Copy link

martin-hirsch commented Aug 22, 2024

Hi everyone,

I'm a regular user of FluentResults and greatly appreciate the flexibility it provides for handling success and failure scenarios in a functional style. However, I often work in scenarios where it would be beneficial to extend the library to better support Railway-Oriented Programming (ROP) by introducing a Result<TValue, TRequest> type.

Proposal

I propose extending the library to include a generic Result<TValue, TRequest> type. This extension would allow users to not only return the result (TValue) but also retain information about the original request (TRequest). This is particularly useful in scenarios where it’s important to maintain context, such as when needing to reference the ID of the original request.

Example

Here’s an example of how this feature could be used:

public class Entity
{
    public Guid Id { get; set; }
    public string Name { get; set; }
}

public class CreateEntityRequest
{
    public Guid RequestId { get; set; }
    public string Name { get; set; }
}

public class EntityService
{
    public Result<Entity, CreateEntityRequest> CreateEntity(CreateEntityRequest request)
    {
        if (string.IsNullOrEmpty(request.Name))
        {
            return Result.Fail<Entity, CreateEntityRequest>("Entity name cannot be empty", request);
        }
        
        var entity = new Entity
        {
            Id = Guid.NewGuid(),
            Name = request.Name
        };

        return Result.Ok<Entity, CreateEntityRequest>(entity, request);
    }
}

I believe this feature would be a valuable addition to FluentResults and would greatly simplify certain types of workflows. I'm happy to discuss this further or provide additional examples if needed.

Thanks for considering this!

Best regards,
Martin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant