Suppose I have a function which populates a few lists like the following:
public static List<T> foo()
{
List<T> bar = List<T>();
List<T> buzz = List<T>();
List<T> bazz = List<T>();
foreach (T item in someList) # Cannot change
{
if (condition1)
{
bar.add(item);
}
if (condition2)
{
buzz.add(item);
}
if (condition3)
{
bazz.add(item);
}
}
return bar;
}
At the moment I only return one list, however I'm interested in returning all the lists since each one contains elements which must be handled differently by the calling function. What should I be returning here? I've considered a tuple of lists, or a list of tuples, but I would expect that there are other designs which would serve this pattern better. Note that unlike the question which was suggested as a duplicate, I'm looking for a solution for an arbitrary number of lists with names.
I can't separate the iteration into separate functions for each list, the actual iteration calls a command which isn't idempotent.
As a bonus, it would be great if the lists were named, so we wouldn't be relying on their position in some tuple or etc but could call them by "bar", "buzz", etc.
`, each iteration is a separate list
– maccettura Jul 16 '18 at 16:54