Introduction
There are two characteristics in higher order function.
- Accept a function as a parameter
- Return a function
Popularity
Higher order function is now implemented in many programming launguage, such as Ruby, javascript,Haskell, especilly it is heavily used in jQuery(A javascript library). In Java, there is no higher order function, but you can wrap the higher oreder function in an annoymous inner class.
jQuery
click is the higher order function, where the function alert a dialog is the parameter passed in
$("#target").click(function() {
alert("Handler for .click() called.");
});
Ruby
There are many higher order function in Array of Ruby, such as each, map, inject but these methods come from the Enumerable mixin.
(1..2).each do |num|
puts num
end
%w{jason sam}.map { |name| name }