Skip to content

Instantly share code, notes, and snippets.

@exallium
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save exallium/9486343 to your computer and use it in GitHub Desktop.

Select an option

Save exallium/9486343 to your computer and use it in GitHub Desktop.
Very simple Function object with composition in Java.
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