Created
April 26, 2018 16:34
-
-
Save nwillc/0e59303a4b900b5bbf62d8cf1eaededc to your computer and use it in GitHub Desktop.
A Before Combinator
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
@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