6 kyu

Function Composition

2,516 of 13,852user578387

Description:

Function composition is a mathematical operation that mainly presents itself in lambda calculus and computability. It is explained well here, but this is my explanation, in simple mathematical notation:

f3 = compose( f1 f2 )
   Is equivalent to...
f3(a) = f1( f2( a ) )

Your task is to create a compose function to carry out this task, which will be passed two functions or lambdas. Ruby functions will be passed, and should return, either a proc or a lambda. Remember that the resulting composed function may be passed multiple arguments!

compose(f , g)(x)
=> f( g( x ) )
compose(f , g).(x)
=> f.( g.( x ) )
compose(f , g)(x)
=> f( g( x ) )
((compose f  g) x)
=> (f (g x) )
compose(f , g)(x)
=> f( g( x ) )
h = compose f g
h x # f (g x)

This kata is not available in haskell; that would be too easy!

Functional Programming
Fundamentals

Stats:

CreatedSep 23, 2014
PublishedSep 25, 2014
Warriors Trained26510
Total Skips5675
Total Code Submissions73758
Total Times Completed13852
Clojure Completions567
Ruby Completions595
Python Completions2516
JavaScript Completions10455
CoffeeScript Completions155
λ Calculus Completions86
Total Stars308
% of votes with a positive feedback rating86% of 861
Total "Very Satisfied" Votes667
Total "Somewhat Satisfied" Votes152
Total "Not Satisfied" Votes42
Ad
Contributors
  • user578387 Avatar
  • jhoffner Avatar
  • alchemy Avatar
  • xcthulhu Avatar
  • JohanWiltink Avatar
  • Voile Avatar
  • Kacarott Avatar
  • farhanaditya Avatar
Ad