Question: `ErrorOr<>.Errors` as readonly collection
Closed this issue · 1 comments
wdolek commented
Is ErrorOr
designed so that you can mutate its state (List<Error> Errors
), or is there any other reason for this design choice?
Using IReadOnlyList<>
(or even IReadOnlyCollection<>
if accessing very first error is not needed) would improve (imo):
- Signature - giving hint that this is immutable data structure
- No need for allocating new
List<Error>
when accessing errors (though this should be relatively cheap, but still additional allocation)- both caching no errors list and empty one
- Only drawback I can see is that to ensure no one tempers with input, copy of input list is needed (in ctor
ErrorOr(List<Error> errors)
)
I'm really interested knowing specific reason (of course changing it to IReadOnly*
is breaking, obviously)
amantinband commented