Created
February 11, 2016 09:38
-
-
Save 4oi/982563337821af742f0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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