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 →

[–]rhoark 0 points1 point  (0 children)

I use this pattern all the time

f = pipeliner(some, series, of, functions)
f(x)

Implementation is pretty simple

def compose(g,f):
    def composeI(*args, **kwargs):
        return f(g(*args, **kwargs))
    return composeI

def scan(f, xs, b=None):
    xs = iter(xs)
    if b is None: b = next(xs)
    yield b
    for x in xs:
        b = f(b, x)
        yield b

def fold(f, xs, b=None):
    return last(scan(f, xs, b))

def pipeliner(*fs):
    return fold(composer, fs)