Skip to content

Instantly share code, notes, and snippets.

@nwillc
Created April 26, 2018 16:34
Show Gist options
  • Save nwillc/0e59303a4b900b5bbf62d8cf1eaededc to your computer and use it in GitHub Desktop.
Save nwillc/0e59303a4b900b5bbf62d8cf1eaededc to your computer and use it in GitHub Desktop.
A Before Combinator
@FunctionalInterface
public interface Before<T, R>
extends Function<Consumer<T>,
Function<Function<T, R>,
Function<T, R>>> {
static <T, R> Before<T, R> create() {
return before -> function -> argument -> {
before.accept(argument);
return function.apply(argument);
};
}
static <T, R> Function<T, R> decorate(
Consumer<T> before,
Function<T, R> function) {
return Before.<T, R>create().apply(before).apply(function);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment