You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
742 B

9 months ago
from cppy.cp_util import *
'''
函数是自由函数,还是正常的函数写法
使用
- 列举函数名首部参数外的其它参数
- 调用 data 得到最后数据
'''
9 months ago
class FunPipe:
def __init__(self, func, *args, **kwargs):
9 months ago
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)
9 months ago
@property
def data(self):
return self.func(*self.args, **self.kwargs)
9 months ago
# 模仿管道
pipe = FunPipe(
extract_file_words,
testfilepath) | FunPipe(get_frequencies) | FunPipe(sort_dict) | FunPipe(
print_word_freqs, 10)
9 months ago
pipe.data