Last active
August 29, 2015 13:57
-
-
Save exallium/9486343 to your computer and use it in GitHub Desktop.
Very simple Function object with composition in Java.
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 abstract class Function<A, B> { | |
| public abstract B apply(A arg); | |
| // Given f :: a -> b and g :: b -> c, we can define h :: a -> c as the composition of f and g | |
| public static <A, B, C> Function<A, C> compose(final Function<A, B> x, final Function<B, C> y) { | |
| return new Function<A, C>() { | |
| @Override | |
| public C apply(A arg) { | |
| return y.apply(x.apply(a)); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment