Skip to content

Instantly share code, notes, and snippets.

@tazjin
Created October 20, 2016 17:02
Show Gist options
  • Select an option

  • Save tazjin/d71d9eb0e02f14488f779283e3de862b to your computer and use it in GitHub Desktop.

Select an option

Save tazjin/d71d9eb0e02f14488f779283e3de862b to your computer and use it in GitHub Desktop.
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