首页 > 代码库 > 【codewar】
【codewar】
##题目描述
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 ) )
##思路分析
和7kyu的Unary function chainer 有点像
##代码解析
1 def compose(f,g):2 return lambda *x: f(g(*x))
注意lambda 和 * 的用法
【codewar】
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。