Skip to main content

Python 函数式编程工具集

Project description

vools - Python 函数式编程工具集

一个强大的 Python 函数式编程工具集,提供装饰器、函数式编程工具、数据处理工具等。

项目结构

vools/
├── vools/
│   ├── data/            # 数据处理工具
│   │   ├── __init__.py
│   │   └── seq.py          # 序列操作工具
│   ├── datetime/        # 日期时间工具
│   │   ├── __init__.py
│   │   ├── dates_format.py
│   │   ├── range.py
│   │   └── utils.py
│   ├── decorators/      # 装饰器
│   │   ├── __init__.py
│   │   ├── cache.py
│   │   ├── control.py
│   │   ├── curry.py
│   │   ├── curry_core.py
│   │   ├── curry_delay.py
│   │   ├── extend.py
│   │   ├── lazy.py
│   │   ├── overload.py
│   │   ├── overcurry.py
│   │   ├── selector.py
│   │   └── trd.py
│   ├── functional/      # 函数式编程工具
│   │   ├── __init__.py
│   │   ├── arrow_func.py
│   │   ├── box.py
│   │   └── placeholder.py
│   ├── oop/             # OOP 工具
│   │   ├── __init__.py
│   │   ├── calltype.py
│   │   ├── extend.py
│   │   └── selector.py
│   ├── utils/           # 通用工具
│   │   ├── __init__.py
│   │   └── stuff.py
│   ├── __init__.py
│   └── vools.py         # 核心功能
├── tests/              # 测试文件
│   ├── __init__.py
│   ├── test_curried.py
│   ├── test_curry_overload.py
│   ├── test_data.py
│   ├── test_datetime.py
│   ├── test_decorators.py
│   ├── test_functional.py
│   ├── test_functional_simple.py
│   ├── test_oop.py
│   ├── test_overcurry_vic.py
│   ├── test_placeholder.py
│   ├── test_shotcut.py
│   ├── test_utils.py
│   └── test_vools.py
├── .gitignore
├── LICENSE
├── NOTICE
├── README.md
├── requirements.txt
├── setup.py
└── USER_GUIDE.md

安装指南

环境要求

  • Python 3.6+

安装方法

  1. 克隆项目
git clone https://github.com/vicTop-cw/vools.git
cd vools
  1. 安装依赖
pip install -r requirements.txt
  1. 配置设置

复制配置模板并填写相应的配置值:

cp vools/config.template.py vools/config.py
# 编辑 vools/config.py 文件,填写配置值

或者通过环境变量设置配置:

# 示例环境变量设置
# export CACHE_DURATION=300

用法指南

装饰器

from vools import memorize, once, repeat, retry

# 缓存装饰器
@memorize(duration=60)  # 缓存 60 秒
def expensive_function(x):
    return x ** 2

# 只执行一次
@once
def initialize():
    print("初始化...")
    return 42

# 重复执行
@repeat(cnt=3, delay=0.1)
def hello(name):
    return f"Hello, {name}!"

# 重试装饰器
@retry(times=3, delay=1)
def risky_operation():
    # 可能失败的操作
    pass

函数式编程工具

from vools import Pipe, Ops, Seq, P

# 使用 Pipe
result = range(10) | Pipe(lambda x: [i * 2 for i in x]) | Pipe(list)

# 使用 Ops
result = range(10) | Ops.filter(lambda x: x % 2 == 0) | Ops.map(lambda x: x * 2) | Ops.sum()

# 使用 Seq
result = Seq(range(10)).map(lambda x: x * 2).filter(lambda x: x > 5).collect()

# 使用 P
result = [1, 2, 3] | P(sum)

数据处理工具

from vools import Seq

# 创建序列并进行操作
result = Seq(range(10))\
    .map(lambda x: x * 2)\
    .filter(lambda x: x > 5)\
    .map(lambda x: x + 1)\
    .collect()

print(result)  # 输出: [7, 9, 11, 13, 15, 17, 19]

# 链式操作
result = Seq([1, 2, 3, 4, 5])\
    .map(lambda x: x ** 2)\
    .filter(lambda x: x > 10)\
    .collect()

print(result)  # 输出: [16, 25]

配置管理

from vools import config

# 获取配置
cache_duration = config.get('OTHER_CONFIG.cache_duration', 5)  # 默认值 5

# 设置配置
config.set('OTHER_CONFIG.max_workers', 20)

# 验证配置
config.validate()

API 文档

装饰器模块

  • memorize(duration=300): 缓存函数结果
  • once(): 函数只执行一次
  • lazy(): 延迟执行函数
  • repeat(cnt=1, delay=0): 重复执行函数
  • retry(times=3, delay=1): 失败时重试
  • rerun(interval=1, times=-1): 定时重复执行
  • trd(): 线程执行
  • proc(): 进程执行
  • extend(): 函数扩展
  • curry(): 柯里化
  • delay_curry(): 延迟柯里化
  • overload(): 函数重载

函数式编程模块

  • Pipe(func): 管道操作
  • Ops: 操作符集合(filter, map, sum, all, any, min, max, take, drop, distinct, count, as_list, do)
  • Seq(iterable): 序列操作(map, filter, collect)
  • P(func): 可管道化函数包装器
  • NONE: 空值标记

数据处理模块

  • box(obj): 将对象包装为 Box 对象,提供链式操作
  • Box(obj): Box 类,用于包装对象并提供链式操作

配置管理

  • config.get(key, default=None): 获取配置值
  • config.set(key, value): 设置配置值
  • config.get_all(): 获取所有配置
  • config.validate(): 验证配置

贡献指南

  1. Fork 项目
  2. 创建功能分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 打开 Pull Request

代码规范

  • 遵循 PEP 8 代码风格
  • 使用 Black 进行代码格式化
  • 使用 isort 进行导入排序
  • 为所有公共函数添加文档字符串
  • 为新功能添加测试

许可证

本项目采用 Apache 2.0 许可证 - 详见 LICENSE 文件

联系方式

更新日志

v0.1.0

  • 初始版本
  • 实现装饰器模块
  • 实现函数式编程工具
  • 实现数据处理工具
  • 实现配置管理
  • 添加基本测试

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vools-0.1.1.tar.gz (136.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vools-0.1.1-py3-none-any.whl (157.5 kB view details)

Uploaded Python 3

File details

Details for the file vools-0.1.1.tar.gz.

File metadata

  • Download URL: vools-0.1.1.tar.gz
  • Upload date:
  • Size: 136.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for vools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f91ec02c5faa1d86695471a7ecdd014d826376cc0bc907cad2c4f6b2602d6974
MD5 2f2debb5d1f6304687cfac2e57a7aea6
BLAKE2b-256 395de74796da3e85541759e048e2a3c96b42c1791eba40e0e9f6f29d3b7f5981

See more details on using hashes here.

File details

Details for the file vools-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: vools-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 157.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for vools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c76c160fbb557f72f513628f3707634f0f21b452e2c8bbf2d66533de3f1b3f98
MD5 ba01561b9a43b4465df0c9f69f1cc182
BLAKE2b-256 ecb3e3f9149c611fe380bfe9f5aa499e6b4652a8f131202eb6c8176f93759871

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page