Sorry for the lack of a descriptive title; I couldn't think of anything better. Edit it if you think of one.
Let's say I have two List
s of Objects, and they are always changing. They need to remain as separate lists, but many operations have to be done on both of them. This leads me to doing stuff like:
//assuming A and B are the lists
A.foo(params)
B.foo(params)
In other words, I'm doing the exact same operation to two different lists at many places in my code. I would like a way to reduce them down to one list without explicitly having to construct another list. I know that just combining lists A
and b
into a list C
would solve all my problems, but then we'd just be back to the same operation if I needed to add a new object to the list (because I'd have to add it to C
as well as its respective list).
It's in a tight loop and performance is very important. Is there any way to construct an iterator or something that would iterate A
and then move on to B
, all transparently? I know another solution would be to construct the combined list (C
) every time I'd like to perform some kind of function on both of these lists, but that is a huge waste of time (computationally speaking).