def thread_last(val, *forms):
    def evalform_back(val, form):
        if callable(form):
            return form(val)
        if isinstance(form, tuple):
            func, args = form[0], form[1:]
            args = args + (val,)
            return func(*args)
    return reduce(evalform_back, forms, val)
Thread value through a sequence of functions/forms
dataset/ETHPy150Open pytoolz/toolz/toolz/functoolz.py/thread_last