implementation of "composition" and usage
static Func<Ta, Tc> Compose<Ta, Tb, Tc>(
Func<Tb, Tc> g,
Func<Ta, Tb> f
) {
return x => g(f(x));
}
// use:
var h = Compose(g,f);
# Patch Proc and add * operator
class Proc
def self.compose(g, f)
lambda { |*args| g[f[*args]] }
end
def *(f)
Proc.compose(self, f)
end
end
# use:
h = g * f
#include <functional>
template <typename A, typename B, typename C>
std::function<C(A)> compose(
std::function<C(B)> g,
std::function<B(A)> f
) {
return [g,f](A x) { return g(f(x)); };
}
// use:
auto h = compose(g,f);
const compose = (g, f) => x => g(f(x));
// use:
const h = compose(g,f);
def compose(g, f):
return lambda x: g(f(x))
# use:
h = compose(g,f)
Compose natively exists in form of the . operator
h = g . f