GregSmalter / TEWL

The Toolkit for the Enterprise Web Library. This can be used to conveniently gain validation, IO, and string manipulation functions without subscribing to the whole library lifecycle.
MIT License
2 stars 2 forks source link

Removed a Concat overload in CollectionTools #28

Closed william-gross closed 4 months ago

william-gross commented 9 months ago

It appears to be error-provocative. If this method is important, I'd support restoring it under a different name.

GregSmalter commented 8 months ago

An example of it causing a problem would be helpful. If you want to rename it to ConcatIndividualItem we could see how that goes.

william-gross commented 4 months ago

I did the rename, to ConcatItems. And for reference, here are the problems I saw with this when it was an overload:

  1. You could accidentally call .Concat(), with no arguments, which is probably a mistake.
  2. You could change the collection element type from a single object to a nested collection and have your code reinterpreted rather than breaking. See below:
var original = new List<int> { 1, 2 };
var hasFour = original.Concat( [ 3, 4 ] );

// Now we're making each element a pair, and will accidentally end up with three total items instead of four.
var modified = new List<int[]> { new[] { 1, 0 }, new[] { 2, 0 } };
var shouldHaveFourButWontBreak = modified.Concat( [ 3, 4 ] );