如何从 Python 中促进延续传递风格?
(我认为这是正确的术语)
我的代码开始变得乱七八糟,我有map
sfilter
和 s 链,lambda
如下所示:
(lambda a,b: (lambda c:(lambda d: d*d)(c-b))(a*b))(5,6)
“管道表达式”可以在多种语言中找到,例如:
F#解决方案(例如|>
:)
let complexFunction =
2 (* 2 *)
|> ( fun x -> x + 5) (* 2 + 5 = 7 *)
|> ( fun x -> x * x) (* 7 * 7 = 49 *)
|> ( fun x -> x.ToString() ) (* 49.ToString = "49" *)
Haskell解决方案(例如:do
、管道)
main = do
hSetBuffering stdout NoBuffering
str <- runEffect $
("End of input!" <$ P.stdinLn) >-> ("Broken pipe!" <$ P.stdoutLn)
hPutStrLn stderr str
JavaScript(例如:async.js):
async.waterfall([
function(callback) {
callback(null, 'one', 'two');
},
function(arg1, arg2, callback) {
// arg1 now equals 'one' and arg2 now equals 'two'
callback(null, 'three');
},
function(arg1, callback) {
// arg1 now equals 'three'
callback(null, 'done');
}
], function (err, result) {
// result now equals 'done'
});
但是我知道最后一个策略更多的是用于异步函数响应解析(请参阅:回调地狱)。