from cppy.cp_util import *

'''
函数是自由函数,还是正常的函数写法
使用，
  - 列举函数名，首部参数外的其它参数
  - 调用 data 得到最后数据
'''
  
class FunPipe:
    def __init__(self, func, *args, **kwargs):        
        self.func = func
        self.args = args
        self.kwargs = kwargs

    def __or__(self, other):
        _data = self.func(*self.args, **self.kwargs)                     
        return FunPipe( other.func,_data,*other.args,**other.kwargs)

    @property
    def data(self):
        return self.func(*self.args, **self.kwargs)   


# 模仿管道
pipe = FunPipe(extract_file_words,testfilepath) | FunPipe(get_frequencies) | FunPipe(sort_dict) | FunPipe(print_word_freqs, 10)
pipe.data

