For example, given the two functions
f(x) = x + 2
g(x) = 3x
find the composition of g(f(2)) means to first evaluate f(2) and then substitute that value into x of g(x) to obtain the final result.
Since f(2) = 2 + 2 = 4
Substituting 4 into x in the g(x) equation yields
g(4) = 3*4 = 12
so g(f(2)) = 12
Functional composition can be extended to 3 or as many functions as you like. Simply take the output of the function and feed it into the independent variable of another function. Then take that output and feed it into another function.
Functional programming works along the same math based mindset. Functional programming takes an output of a function, such as a JavaScript function and feeds it into another function You can chain together as many JavaScript functions as you like.
Other concepts such as recursion also come into play in functional programming. Recursion, is slightly different than functional composition. Instead of feeding the output of the function into the independent variable of another function, you feed the output of one function back into the independent variable of the same function.
Posted By: Mark Stansberry, www.bookmarktutorin.com on Sept 18 2014
BookMarkTutoring.com offers onSite, onCall, onLine and inPerson tutoring in math, science, computer programming and graphic design.
No comments:
Post a Comment