Closed GregOnNet closed 2 years ago
Idea Maybe, we could improve .combine
even more providing a better experience.
const user = Result.success({ name: 'Somebody' });
const order = Result.success({ name: 'Some Name' });
const result = Result.combine({ user, oder }).map(({ user, order }) => ... )
// ^ Result value combines values of all Results.
... Working on better typings as seen for the pipe-Operator
Added types and a few tests.
Nice readable tests! 👍
Introducing Record in favour of using tuples. Reason: Accessing members of a Record is more readable.
// Current Implementation
Result.combine( result1, result2).map(results => results[0] ...)
// vs. Record
Result.combine({ result1, result2 }).map(results => results.result1)
Thanks, @KyleMcMaster, I updated the implementation.
Let me know if I can improve something.
Hi @seangwright & @KyleMcMaster,
the PR is ready for review. 👍
Description
Allows combining multiple results into one. Error Message of failing results are concatenated.
CSharp Functional Extensions provide a similar feature: https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/master/CSharpFunctionalExtensions/Result/Methods/Combine.cs#L18
Motivation
If you are using Value Objects to save your domain from invalid values, having a comfortable way of checking all used Value Objects leads to code that is more readable:
Open questions
Currently, only ErrorMessages of type string are supported. Do we want to invest some more time to aggregate Error-Objects as well?