Created
October 20, 2016 17:02
-
-
Save tazjin/d71d9eb0e02f14488f779283e3de862b to your computer and use it in GitHub Desktop.
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
| import java.util.function.Consumer; | |
| import java.util.function.Function; | |
| public class $<T> { | |
| final private Function<T, T> f; | |
| public $(Consumer<T> c) { | |
| this.f = apply(c); | |
| } | |
| private $(Function<T, T> o) { | |
| this.f = o; | |
| } | |
| public $<T> $(Consumer<T> c) { | |
| return new $(compose(c)); | |
| } | |
| public T $(T t) { | |
| return f.apply(t); | |
| } | |
| private Function<T, T> apply(Consumer<T> consumer) { | |
| return (t -> { | |
| consumer.accept(t); | |
| return t; | |
| }); | |
| } | |
| private Function<T, T> compose(Consumer<T> consumer) { | |
| return f.compose(apply(consumer)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment