码迷,mamicode.com
首页 > 其他好文 > 详细

【codewar】

时间:2016-08-30 13:33:18      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

##题目描述

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】

标签:

原文地址:http://www.cnblogs.com/pudding-ai/p/5821612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!