How can Continuation-passing style be facilitated from Python?
(I think that's the right term)
My code is starting to get messy, I have map
, filter
and chains of lambda
s like so:
(lambda a,b: (lambda c:(lambda d: d*d)(c-b))(a*b))(5,6)
"Pipeline expressions" are found in a variety of languages, for example:
F# solution (e.g.: |>
)
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 solution (e.g.: do
, pipes)
main = do
hSetBuffering stdout NoBuffering
str <- runEffect $
("End of input!" <$ P.stdinLn) >-> ("Broken pipe!" <$ P.stdoutLn)
hPutStrLn stderr str
JavaScript (e.g.: 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'
});
However I understand that this last strategy is more for asynchronous function response resolution (see: callback hell).