#NEWLINE# def aggregate( self , * args ) : #NEWLINE# #INDENT# '\n        Aggregates the sequence by specified arguments. Its behavior varies depending on if one,\n        two, or three arguments are passed. Assuming the type of the sequence is A:\n\n        One Argument: argument specifies a function of the type f(current: B, next: A => result: B.\n        current represents results computed so far, and next is the next element to aggregate into\n        current in order to return result.\n\n        Two Argument: the first argument is the seed value for the aggregation. The second argument\n        is the same as for the one argument case.\n\n        Three Argument: the first two arguments are the same as for one and two argument calls. The\n        additional third parameter is a function applied to the result of the aggregation before\n        returning the value.\n\n        :param args: options for how to execute the aggregation\n        :return: aggregated value\n        ' #NEWLINE# seed = None #NEWLINE# result_lambda = identity #NEWLINE# if ( len ( args ) == 1 ) : #NEWLINE# #INDENT# func = args [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( args ) == 2 ) : #NEWLINE# #INDENT# seed = args [ 0 ] #NEWLINE# func = args [ 1 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( args ) == 3 ) : #NEWLINE# #INDENT# seed = result_lambda [ 0 ] #NEWLINE# func = args [ 1 ] #NEWLINE# result_lambda = args [ 2 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'aggregate takes 1-3 arguments, {0} were given' . format ( len ( args ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( args ) == 1 ) : #NEWLINE# #INDENT# return result_lambda ( self . drop ( 1 ) . fold_left ( self . first ( ) , func ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return result_lambda ( self . fold_left ( seed , func ) )