Skip to main content

A brief description of lambdaext

Project description

Extended Lambda Library Documentation

Extended Lambda 库文档

Extended Lambda Logo

Enhancing Functional Programming in Python
增强Python中的函数式编程


Table of Contents / 目录

  1. Introduction / 介绍
  2. Installation / 安装
  3. Core Concepts / 核心概念
  4. API Reference / API参考
  5. Advanced Usage / 高级用法
  6. Examples / 示例

Introduction / 介绍

The Extended Lambda Library is a powerful Python library that enhances functional programming capabilities in Python. It provides a set of tools and higher-order functions that allow for more expressive and concise functional code. This library extends the concept of lambda functions and introduces new ways to compose and manipulate functions.

Extended Lambda 库是一个强大的 Python 库,它增强了 Python 中的函数式编程能力。它提供了一套工具和高阶函数,允许更具表现力和简洁的函数式代码。这个库扩展了 lambda 函数的概念,并引入了组合和操作函数的新方法。


Installation / 安装

To install the Extended Lambda Library, you can use pip:

pip install lambdaext

Or clone the repository and install it locally:

git clone https://github.com/SoulCodingYanhun/lambdaext.git
cd lambdaext
pip install -e .

要安装 Extended Lambda 库,你可以使用 pip:

pip install lambdaext

或者克隆仓库并本地安装:

git clone https://github.com/SoulCodingYanhun/lambdaext.git
cd lambdaext
pip install -e .

Core Concepts / 核心概念

Concept
概念
English 中文
LAMBDA A special object that allows for the use of => and <= like operators in Python. 一个特殊对象,允许在 Python 中使用类似 =><= 的运算符。
lambda_pass Immediately executes a function and returns the result. 立即执行一个函数并返回结果。
lambda_return Returns a callable LambdaWrapper object. 返回一个可调用的 LambdaWrapper 对象。
Composition
组合
Combining multiple functions into a single function. 将多个函数组合成一个单一函数。
Currying
柯里化
Transforming a function that takes multiple arguments into a sequence of functions, each taking a single argument. 将一个接受多个参数的函数转换为一系列函数,每个函数接受一个参数。

API Reference / API参考

Basic Operations / 基本操作

Operation
操作
English 中文
LAMBDA >> func Equivalent to lambda_pass(func) 等同于 lambda_pass(func)
LAMBDA << func Equivalent to lambda_return(func) 等同于 lambda_return(func)

Higher-Order Functions / 高阶函数

Function
函数
English 中文
compose(*funcs) Composes multiple functions from right to left. 从右到左组合多个函数。
pipe(*funcs) Composes multiple functions from left to right. 从左到右组合多个函数。
curry(func) Returns a curried version of the function. 返回函数的柯里化版本。
map_func(func) Returns a new function that applies func to each element of an iterable. 返回一个新函数,该函数将 func 应用于可迭代对象的每个元素。
filter_func(predicate) Returns a new function that filters an iterable using the given predicate. 返回一个新函数,该函数使用给定的谓词过滤可迭代对象。
reduce_func(func) Returns a new function that reduces an iterable using the given function. 返回一个新函数,该函数使用给定的函数归约可迭代对象。

Advanced Functions / 高级函数

Function
函数
English 中文
keyword_params_func(func) Handles functions that only accept keyword arguments. 处理只接受关键字参数的函数。
combined_params_func(func) Handles functions that accept positional, variable, and keyword arguments. 处理接受位置参数、可变参数和关键字参数的函数。
conditional_func(condition, true_func, false_func) Implements conditional expression functionality. 实现条件表达式功能。
list_comp_func(condition) Implements list comprehension functionality. 实现列表推导式功能。
dict_comp_func(condition) Implements dictionary comprehension functionality. 实现字典推导式功能。
nested_func(outer_func, inner_func) Creates nested functions. 创建嵌套函数。
immediate_func(func, arg) Immediately calls the given function and returns the result. 立即调用给定函数并返回结果。

Advanced Usage / 高级用法

The Extended Lambda Library allows for complex function compositions and manipulations. Here are some advanced usage patterns:

  1. Function Composition
  2. Currying
  3. Conditional Lambda

Extended Lambda 库允许复杂的函数组合和操作。以下是一些高级用法模式:

  1. 函数组合
  2. 柯里化
  3. 条件 Lambda

Examples / 示例

1. Using LAMBDA operators / 使用 LAMBDA 运算符

from lambdaext import LAMBDA

double = LAMBDA >> (lambda x: x * 2)
triple = LAMBDA << (lambda x: x * 3)

print(double(5))    # Output: 10
print(triple(5)())  # Output: 15
from lambdaext import LAMBDA

double = LAMBDA >> (lambda x: x * 2)
triple = LAMBDA << (lambda x: x * 3)

print(double(5))    # 输出: 10
print(triple(5)())  # 输出: 15

2. List manipulation / 列表操作

from lambdaext import map_func, filter_func, reduce_func

numbers = [1, 2, 3, 4, 5]
doubled = list(map_func(lambda x: x * 2)(numbers))
evens = list(filter_func(lambda x: x % 2 == 0)(doubled))
total = reduce_func(lambda x, y: x + y)(evens)

print(doubled)  # Output: [2, 4, 6, 8, 10]
print(evens)    # Output: [2, 4, 6, 8, 10]
print(total)    # Output: 30
from lambdaext import map_func, filter_func, reduce_func

numbers = [1, 2, 3, 4, 5]
doubled = list(map_func(lambda x: x * 2)(numbers))
evens = list(filter_func(lambda x: x % 2 == 0)(doubled))
total = reduce_func(lambda x, y: x + y)(evens)

print(doubled)  # 输出: [2, 4, 6, 8, 10]
print(evens)    # 输出: [2, 4, 6, 8, 10]
print(total)    # 输出: 30

3. Complex composition / 复杂组合

from lambdaext import compose, curry, map_func

@curry
def add(x, y):
    return x + y

increment = add(1)
double = lambda x: x * 2

process = compose(
    list,
    map_func(double),
    map_func(increment)
)

result = process([1, 2, 3, 4, 5])
print(result)  # Output: [4, 6, 8, 10, 12]
from lambdaext import compose, curry, map_func

@curry
def add(x, y):
    return x + y

increment = add(1)
double = lambda x: x * 2

process = compose(
    list,
    map_func(double),
    map_func(increment)
)

result = process([1, 2, 3, 4, 5])
print(result)  # 输出: [4, 6, 8, 10, 12]

Extended Lambda Library: Elevating Functional Programming in Python
Extended Lambda 库: 提升 Python 中的函数式编程

GitHub | Documentation | PyPI | CodeStarLabs

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

lambdaext-1.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

lambdaext-1.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file lambdaext-1.0.1.tar.gz.

File metadata

  • Download URL: lambdaext-1.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for lambdaext-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c2a4dcd57e96cccf0105e7b417ce70def9c37a2e2d06526a63f604cc765a28fb
MD5 8f29900f1db3e14ef448a104731bf9fa
BLAKE2b-256 faa7d9357b533e6c028db32a0fd69cb673b3e03003e8169ba4b51d05a9653c51

See more details on using hashes here.

File details

Details for the file lambdaext-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: lambdaext-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for lambdaext-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa4e003fc075ecbe5b3e127645f9304e4fd38ae9462d6a8961935a5b3b6749ed
MD5 be0c5b223e07a733724adef5a12d8c77
BLAKE2b-256 d8f0acdf28c248fff0e7ccd28ce66fc7f84ffe0b89cf47038abc9f32ca1fe99f

See more details on using hashes here.

Supported by

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