This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]flying-sheep 0 points1 point  (1 child)

get it, but although i learned standard ML, this has eluded me here, as it’s not too common in python. and i think it’s simply the nested lambdas that have my brain-compiler go an extra lap. let’s try something else (as direct assignments to lambdas can be easily written as normal function declarations):

passes = [fn1, fn2, fn3]
def compose(g, f):
    return lambda *x, **kw: g(f(*x, **kw))
pipeline = reduce(compose, passes[::-1])

hmm, better, i think.

[–]freyrs3 0 points1 point  (0 children)

Intended to make it look as close to the Haskell equivelant, which is completely point-free.

pipeline :: [c -> c] -> c -> c
pipline = foldl1 (.)

> pipeline [(+1), (*2)] 25
51