用python实现的功能管道
functional-pipeline的Python项目详细描述
功能管道
函数语言如Haskell、IrxIR和ELM具有允许 一个函数传递给下一个函数的结果。使用functools
中的函数,我们可以在python中构建组合,但是它不是
几乎和精心设计的管道一样优雅。
这个库的设计是为了在python中更轻松地创建功能管道。
>>>fromoperatorimportadd,mul>>>fromfunctional_pipelineimportpipeline,tap>>>result=pipeline(...10,...[...(add,1),...(mul,2)...]...)>>>result22
此模式可以扩展,以便轻松处理列表或生成器。
>>>fromfunctional_pipelineimportpipeline,String,join>>>names=[..."John",..."James",..."Bill",..."Tiffany",..."Jamie",...]>>>result=pipeline(...names,...[...(filter,String.startswith('J')),...(map,lambdax:x+" Smith"),...join(", "),...]...)>>>result'John Smith, James Smith, Jamie Smith'