#NEWLINE# def thread_last( val , * forms ) : #NEWLINE# #INDENT# ' Thread value through a sequence of functions/forms\n\n    >>> def double(x): return 2*x\n    >>> def inc(x):    return x + 1\n    >>> thread_last(1, inc, double)\n    4\n\n    If the function expects more than one input you can specify those inputs\n    in a tuple.  The value is used as the last input.\n\n    >>> def add(x, y): return x + y\n    >>> def pow(x, y): return x**y\n    >>> thread_last(1, (add, 4), (pow, 2))  # pow(2, add(4, 1))\n    32\n\n    So in general\n        thread_last(x, f, (g, y, z))\n    expands to\n        g(y, z, f(x))\n\n    >>> def iseven(x):\n    ...     return x % 2 == 0\n    >>> list(thread_last([1, 2, 3], (map, inc), (filter, iseven)))\n    [2, 4]\n\n    See Also:\n        thread_first\n    ' #NEWLINE# def evalform_back( val , form ) : #NEWLINE# #INDENT# if callable ( form ) : #NEWLINE# #INDENT# return form ( val ) #NEWLINE# #UNINDENT# if isinstance ( form , tuple ) : #NEWLINE# #INDENT# ( func , args ) = ( form [ 0 ] , form [ 1 : ] ) #NEWLINE# args = ( args + ( val , ) ) #NEWLINE# return func ( * args ) #NEWLINE# #UNINDENT# #UNINDENT# return reduce ( evalform_back , forms , val )