高阶函数和效用函数的集合
ftoolz的Python项目详细描述
自由贸易区
建立在cytoolz
之上的高阶函数和实用函数的集合。
模块概述
ftoolz被分成几个通用模块。
ADT包
为各种抽象数据类型(ADT)提供实现的包。
ADT | Description |
---|---|
^{ | mutable iterator that can be both consumed and appended to, optionally initialized with init state ^{ |
functoolz包
提供通常与函子、applicative和monad相关联的高阶函数的包。
此外,在__init__.py
中实现了一般的包级函数。
Function | Description |
---|---|
^{ | equivalent to ^{ |
^{ | reversed function composition ^{ |
^{ | decorator that silences (selected/all) errors raised by decorated function |
^{ | equivalent to ^{ |
^{ | ^{ |
包内容按单个类型分类组织为模块:
iter.py
对于类Iterable
。warn某些函数可能不是纯函数,因为已使用input iterable。opt.py
对于类Optional
seq.py
对于类Seq
(Sequece
)。方法通常返回tuple
实例以保持不变性。
模块功能概述
def / .py | iter | opt | seq |
---|---|---|---|
^{ | x | x | x |
^{ | - | x | - |
^{ | - | + | - |
^{ | x | x | x |
^{ | x | x | x |
^{ | x | x | x |
^{ | x | x | x |
^{ | - | x | - |
^{ | - | + | - |
^{ | x | x | x |
^{ | x | - | x |
^{ | x | x | x |
^{ | x | x | x |
^{ | x | * | x |
^{ | + | - | + |
x
-实现,静态类型检查+
-实现,可能的运行时类型错误*
-未实现,本机支持-
-未实现
遍历包
每个模块都包含可遍历的相关函数,用于可遍历的Iterable
和Seq
。
单个模块被命名并保留给包装可遍历序列元素的单个函子。
模块(函子)中当前实现的函数列表:
def / .py | opt |
---|---|
^{ | x |
^{ | x |
^{ | x |
^{ | x |
不安全包装
包unsafe
专用于所有impure函数,这些函数倾向于或
会直接使用副作用。
反射
此模块包含类发现、检查和 修改。
目录
Function | Description |
---|---|
^{ | ^{ |
^{ | discover all non-protected implementations of ^{ |
^{ | recursively import everything under ^{ |
^{ | ^{ |
^{ | discover all subclasses of ^{ |
dicttoolz
此模块包含与Map
(Mapping
)实例一起工作的函数。
目录
Function | Description |
---|---|
^{ | apply value transformation ^{ |
^{ | swap arbitrary values for ^{ |
^{ | same as ^{ |
伊托奥尔兹
此模块包含与Iterable
实例一起工作的函数。
目录
Function | Description |
---|---|
^{ | associate elements of iterable to keys selected by ^{ |
^{ | associate values obtained from iterable by ^{ |
selected by ^{ | |
^{ | materialize iterable into a sequence if it's not one already |
^{ | check if iterable is empty, returns flag and unchanged iterable |
^{ | same as ^{ |
^{ | filter out ^{ |
^{ | find first element of iterable satisfying predicate |
^{ | return first element of a sequence or ^{ |
^{ | fold iterable by applying binary operator ^{ |
^{ | split iterable into head element and tail iterable |
^{ | same as ^{ |
^{ | creates iterable of tuples of original element and final flag |
^{ | return last element of a sequence or ^{ |
^{ | create string of tokens from iterable selected by ^{ |
^{ | order ^{ |
^{ | collect positions of non-unique items in original sequence |
^{ | split elements of iterable by predicate to positives and negatives |
^{ | take first n elements of an iterable |
^{ | take first element of an iterable or fail |
^{ | same as ^{ |
^{ | take last element of an iterable or ^{ |
^{ | return distinct elements of an iterable as ^{ |
^{ | return distinct elements of an iterable in natural order as ^{ |
谓词
此模块包含公共的Predicate
,即从泛型或具体的A
到bool
的函数。
目录
Predicate | Description |
---|---|
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
键入
类型包含有用的类型别名和其他与类型相关的定义。
cytoolz
cytoolz是python库的cython实现,支持称为 toolz。
我们强烈建议您阅读api文档并在项目中使用它。
ftoolz不分叉,而是扩展cytoolz并为其api提供类型化存根。 请注意,键入的存根不包括cytoolz的所有功能。
另外,由于python的有限类型功能,可能无法涵盖一些有效的情况。
设置开发环境
强烈建议使用虚拟环境开发和测试ftoolz
。为了让事情变得简单
设置两个目标ftoolz
:
make setup
创建由pipenv
管理的新虚拟环境,同时具有dev和ftoolz
依赖项。make install
与make setup
相同,但仅安装ftoolz
依赖项。
要在pipenv环境中运行python控制台,请运行:
pipenv shell
对于运行特定命令:
pipenv run <command>
运行检查和测试
类型检查
类型检查是使用mypy
(有关配置,请参见mypy.ini
)完成的,可以由执行:
make type-check
代码样式检查
ftoolz使用Flake8来强制执行pep 8和其他代码气味。
make flake8-check
起毛
linting在.pylintrc
中配置,可以通过:
make lint
测试
具有覆盖率的单元和文档测试可以由运行
make tests
您还可以通过
make release-check
note:所有这些命令都在python管理的通过pipenv
。
分布
project使用setuptools
进行分发。检查setup.py
中的设置。