Skip to content

Instantly share code, notes, and snippets.

@4oi
Created February 11, 2016 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4oi/982563337821af742f0f to your computer and use it in GitHub Desktop.
Save 4oi/982563337821af742f0f to your computer and use it in GitHub Desktop.
import java.util.function.Supplier;
public class Test {
public static void main(String...args) {
new If(true).then(() -> System.out.println("True")).orElse(() -> System.out.println("False"));
}
public static class If {
boolean b;
public If(boolean b) {
this.b = b;
}
public If then(Runnable r) {
Object tmp = b ? toSupplier(r).get() : null;
return this;
}
public If orElse(Runnable r) {
Object tmp = !b ? toSupplier(r).get() : null;
return this;
}
private static Supplier<?> toSupplier(Runnable r) {
return () -> {
r.run();
return null;
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment