g, and produces a function: function o(f, g) { return function(x) { return f(g(x)); } } // Alternatively, using the rest operator and lambda expressions in ES2015 const compose = (...fs) => (x) => fs.reduceRight((acc, f) => f(acc), x) C# In C# we can define it as a Func which takes two Funcs f and g, and produces a Func: // Call example: // var c = Compose(f, g); // // Func<int, bool> g = _ => ... // Func<bool, string> f = _ => ... Func<T, T> Compose<T>(params Func<T, T>[] xs) => xs.Aggregate((accum, item) => x => accum(item(x))); Ruby Languages like Ruby let you construct a binary operator yourself: class Proc def compose(other_fn) ->(*as) { other_fn.call(call(*as)) } end alias_method :+, :compose end f = ->(x) { x * 2 } g = ->(x) { x ** 3 } (f + g).call(12) # => 13824However, a native function composition operator was introduced in Ruby 2.6: f = proc{|x| x + 2} g = proc{|x| x * 3} (f << g).call(3) # -> 11; identical to f(g(3)) (f >> g).call(3) # -> 15; identical to g(f(3)) Research survey Notions of composition, including the principle of compositionality and composability, are so ubiquitous that numerous strands of research have separately evolved. The following is a sampling of the kind of research in which the notion of composition is central. directly applied function composition to the assemblage of building blocks known as 'monads' in the Haskell programming language. addressed the software reuse problem in terms of composability. formally defined a proof rule for functional composition that assures a program's safety and liveness. identified a strengthened form of compositionality by placing it into a semiotic system and applying it to the problem of structural ambiguity frequently encountered in computational linguistics. examined the role of compositionality in analog aspects of natural language processing. According to a review by , formal treatment of composition underlies validation of component assembly in visual programming languages like IBM's Visual Age for the Java language. Large-scale composition Whole programs or systems can be treated as functions, which can be readily composed if their inputs and outputs are well-defined. Pipelines allowing easy composition of filters were so successful that they became a design pattern of operating systems. Imperative procedures with side effects violate referential transparency and therefore are not cleanly composable. However if one considers the "state of the world" before and