Skip to main content

Python lambda extension library

Project description

Lambda-U

Lambda-U 是一个轻量级的 Python 函数式编程工具库,提供了丰富的函数式编程工具和集合操作方法,帮助开发者写出更简洁、优雅的代码。

✨ 主要特性

  • 🛠 丰富的函数式编程工具(compose、pipe、curry 等)
  • 📦 强大的集合操作(group_by、flatten、chunk 等)
  • ⛓ 支持优雅的链式调用
  • 🎯 完整的类型提示支持
  • 🧪 全面的单元测试覆盖
  • 📝 详细的文档说明

🚀 快速开始

安装

pip install lambda-u

使用

from lambda_u import LambdaBuilder, CollectionUtils, FunctionalUtils

函数组合

f = lambda x: x * 2
g = lambda x: x + 1
composed = LambdaBuilder.compose(f, g)
print(composed(3))  # 输出: 8

函数管道

result = pipe(
1,
lambda x: x + 1,
lambda x: x 2
) # 输出: 4

柯里化

@curry
def add(x, y):
return x + y
add_one = add(1)
result = add_one(2) # 输出: 3

集合操作

分组

users = [
{"name": "Alice", "age": 20},
{"name": "Bob", "age": 20},
{"name": "Charlie", "age": 25}
]
by_age = group_by(users, key="age")
# 输出: {20: [{'name': 'Alice', 'age': 20}, {'name': 'Bob', 'age': 20}], 25: [{'name': 'Charlie', 'age': 25}]}

展平嵌套列表

nested = [[1, 2], [3, 4]]
flat = flatten(nested) # 输出: [1, 2, 3, 4]
# 输出: [1, 2, 3, 4, 5, 6]

分块

numbers = [1, 2, 3, 4, 5, 6]
chunks = chunk(numbers, size=2) # 输出: [[1, 2], [3, 4], [5, 6]]

📚 API 文档

functional 模块

  • compose(*functions): 从右到左组合多个函数
  • pipe(value, *functions): 将值通过一系列函数传递
  • curry(func): 函数柯里化装饰器

collections 模块

  • group_by(items, key): 根据键对集合进行分组
  • flatten(items): 展平嵌套列表
  • chunk(items, size): 将列表分割成固定大小的块

更多 API 详情请查看完整文档

🤝 贡献指南

欢迎提交 Pull Request 和 Issue!在提交之前,请确保:

  1. 更新或添加相应的测试
  2. 更新相关文档
  3. 遵循项目的代码风格

📄 许可证

本项目采用 MIT 许可证。详见 LICENSE 文件。

🔗 相关链接

⭐️ 致谢

感谢所有贡献者对项目的支持!

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

lambda_u-0.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

lambda_u-0.1.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file lambda_u-0.1.0.tar.gz.

File metadata

  • Download URL: lambda_u-0.1.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.1

File hashes

Hashes for lambda_u-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a234f770f08f82aea35123501061706217c2daac0af585d87930730bc460192e
MD5 8c109291f40370e9a6635ecf2999a05b
BLAKE2b-256 36aeb35cfa86abbf2535d9a8bd68b9b1f49083aaccf5b12c6372705adf97861d

See more details on using hashes here.

File details

Details for the file lambda_u-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lambda_u-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.1

File hashes

Hashes for lambda_u-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10e10123a91d9148ffb2b5d5f9530a288c8f168a591f28c02ed6958d68788081
MD5 ce4f5c904f8301f106bc9bfc8791c203
BLAKE2b-256 00a2c6dd173ec87f85272c3abfdf15ccc74cdd3f3abfd4e1dfb7159ae8fa9ac8

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