>>4
Or rather, his abstraction isn't very useful as all it does it get rid of an if, and you still have to keep writing the loop to iterate over the damn things. This is a little more reasonable but :
public abstract class Action<T> {
public abstract void action(T o);
};
public abstract class Filter<T> {
public abstract boolean pass(T o);
};
void <T> Apply(Collection<T> things, Action<T> a = new NullAction<T>(), Filter<T> f = new FilterTrue<T>()) {
for(T t : things)
if(f.pass(t))
a.action(t);
}
...
Collection<Anus> anii = getAnuses();
Apply(anii,
new Action<Anus>() {
public void action(Anus a) { a.hax(); } },
new Filter<Anus>() {
public boolean pass(Anus a) { return a.hasShit(); } });
but still a lot more verbose than
for(Anus a : anii)
if(a.hasShit())
a.hax();
But being Java, there's really no succinct way to create lambdae. This is why I'm enjoying C++11 much more than I normally would C++... and of course you can do this in C:
#define APPLY_FILTER(V,F,E) for(int V=0;V<(LENGTH);V++) if(F) { E; }
APPLY_FILTER(i,anuses[i]->hasShit(),anuses[i]->hax())