amantinband/error-or

Question: `ErrorOr<>.Errors` as readonly collection

Closed this issue · 1 comments

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):

  1. Signature - giving hint that this is immutable data structure
  2. 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
  3. 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)

Hey @wdolek! We've discussed this topic here: #26