Skip to content

Instantly share code, notes, and snippets.

@theqp

theqp/Pipe.java Secret

Created September 2, 2020 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theqp/bc8ca78ea961ef1dab6b85aa28a72952 to your computer and use it in GitHub Desktop.
Save theqp/bc8ca78ea961ef1dab6b85aa28a72952 to your computer and use it in GitHub Desktop.
import java.util.function.Function;
public class Pipe {
private Pipe() {}
public static <V, F1, R> R pipe(V v, Function<V, F1> f1, Function<F1, R> f2) {
return f2.apply(f1.apply(v));
}
public static <V, F2, F3, R> R pipe(
V v, Function<V, F2> f1, Function<F2, F3> f2, Function<F3, R> f3) {
return f3.apply(f2.apply(f1.apply(v)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment