monad-函数库
monad的Python项目详细描述
简介
什么?
python中的monad,以及一些有用的函数。
怎么做?
>>> from monad.decorators import maybe >>> parse_int = maybe(int) >>> parse_int(42) Just(42) >>> parse_int('42') Just(42) >>> parse_int('42.2') Nothing >>> parse_float = maybe(float) >>> parse_float('42.2') Just(42.2) >>> from monad.actions import tryout >>> parse_number = tryout(parse_int, parse_float) >>> tokens = [2, '0', '4', 'eight', '10.0'] >>> [parse_number(token) for token in tokens] [Just(2), Just(0), Just(4), Nothing, Just(10.0)] >>> @maybe ... def reciprocal(n): ... return 1. / n >>> reciprocal(2) Just(0.5) >>> reciprocal(0) Nothing >>> process = parse_number >> reciprocal >>> process('4') Just(0.25) >>> process('0') Nothing >>> [process(token) for token in tokens] [Just(0.5), Nothing, Just(0.25), Nothing, Just(0.1)] >>> [parse_number(token) >> reciprocal for token in tokens] [Just(0.5), Nothing, Just(0.25), Nothing, Just(0.1)] >>> [parse_number(token) >> reciprocal >> reciprocal for token in tokens] [Just(2.0), Nothing, Just(4.0), Nothing, Just(10.0)]
为什么?
为什么不呢。
要求
- cpython=2.7
安装
从pypi安装:
pip install monad
从源安装,下载源包,解压缩,然后cd到源目录,运行:
make install
许可证
bsd new,请参阅许可证以了解详细信息。
链接
- 文档:
- http://monad.readthedocs.org/
- 问题跟踪器:
- https://bitbucket.org/pyx/monad/issues/
- 源包@pypi:
- https://pypi.python.org/pypi/monad/
- Mercurial存储库@BitBucket:
- https://bitbucket.org/pyx/monad/
- git存储库@github:
- https://github.com/pyx/monad/