Created
October 6, 2014 11:44
-
-
Save SamirTalwar/04cb9dfdaac3ecda97b5 to your computer and use it in GitHub Desktop.
Snippet of Lambdas.java from my FizzBuzz project.
This file contains hidden or 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
| public final class Lambdas { | |
| public static final Lambda Identity = x -> x; | |
| public static final Lambda True = x -> y -> x; | |
| public static final Lambda False = x -> y -> y; | |
| public static final Lambda Zero = f -> x -> x; | |
| public static final Lambda Succ = n -> f -> x -> f.call(n.call(f).call(x)); | |
| public static final Lambda Pred = n -> f -> x -> n.call(g -> h -> h.call(g.call(f))).call(ignored -> x).call(u -> u); | |
| public static final Lambda IsZero = f -> f.call(x -> False).call(True); | |
| @SuppressWarnings("unused") | |
| public static final Lambda Y = f -> ((Lambda) (x -> f.call(x.call(x)))) | |
| .call(x -> f.call(x.call(x))); | |
| public static final Lambda Z = f -> ((Lambda) (x -> f.call(y -> x.call(x).call(y)))) | |
| .call(x -> f.call(y -> x.call(x).call(y))); | |
| public static final Lambda Add = x -> x.call(Succ); | |
| public static final Lambda Subtract = x -> y -> y.call(Pred).call(x); | |
| public static final Lambda IsLessOrEqual = x -> y -> IsZero.call(Subtract.call(x).call(y)); | |
| public static final Lambda If = p -> t -> f -> p.call(t).call(f); | |
| ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment