shell风格的python pipeline
2014-01-22 13:54
232 查看
源码来自
CoolShell.cn 函数式编程的评论里面。在此收藏一下
CoolShell.cn 函数式编程的评论里面。在此收藏一下
class Pipe(object): def __init__(self, func): self.func = func def __ror__(self, other): def generator(): for obj in other: if obj is not None: yield self.func(obj) return generator() @Pipe def even_filter(num): return num if num % 2 == 0 else None @Pipe def multiply_by_three(num): return num*3 @Pipe def convert_to_string(num): return 'The Number: %s' % num @Pipe def echo(item): print item return item def force(sqs): for item in sqs: pass nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] force(nums | even_filter | multiply_by_three | convert_to_string | echo)
相关文章推荐
- shell script 学习(四)条件判断式的使用:if..then ..fi和 case...esac语句
- [Shell学习笔记] 数组、关联数组和别名使用
- adb shell 命令
- 关于master..xp_cmdshell’的几个错误解决办法
- shell 编程
- 【脚本练习】shell脚本
- 用Powershell启用Windows Azure上的远程桌面服务
- Linux.Shell编程笔记-正则表达式
- SHELL 脚本基本知识
- 用Powershell启用Windows Azure上的远程桌面服务
- shell脚本自动生成C文件模板
- 【android开发工具】之adb shell dumpsys
- shell和正则表达式使用笔记【未完】
- [转]linux shell if 参数
- shell 冒号减号[转]
- 从学习export命令理解Shell环境和…
- Linux操作系统优化Shell脚本
- 【ROM】4.0.4RE-FLEXxx-ShellSHOCK…
- 【ROM】4.0.4RE-FLEXxx-ShellSHOCK…
- Android ADB shell 命令大全