Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

JAVA FILTER PATTERNS

Name: Anonymous 2012-09-29 22:56

Name: Anonymous 2012-09-29 23:00

>sage

Shalom, hymie!

Name: Anonymous 2012-09-29 23:05

>>2
Salaan, goy!

Name: Anonymous 2012-09-29 23:28

abstraction isn't always a good thing, especially in this case. there's no increased understanding and you're not saving any lines of code, and obviously there's decreased performance.

1/10 for using generics

Name: Anonymous 2012-09-30 1:43

>>4

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2012-09-30 4:08

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

Don't change these.
Name: Email:
Entire Thread Thread List