Skip to content

BriHan-Tech/aspis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aspis

A functional programming library for Python that provides composable, curried utility functions for writing clean, declarative code.

Aspis offers a comprehensive collection of tools inspired by functional programming paradigms, including function composition, currying, predicate logic, and data manipulation.

Installation

pip install aspis

Quick Start

The recommended way to use Aspis is to import the common module with an alias:

import aspis.common as A

# Function composition
times_two = A.multiply(2)
add_ten = A.add(10)
transform = A.pipe(times_two, add_ten)

transform(5)  # Returns 20: (5 * 2) + 10

# Working with data
users = [
    {'name': 'Alice', 'age': 30},
    {'name': 'Bob', 'age': 25}
]

get_name = A.prop('name')
names = list(map(get_name, users))  # ['Alice', 'Bob']

Features

Function Composition

Build complex operations from simple, reusable functions:

import aspis.common as A

# pipe executes left-to-right
process = A.pipe(step1, step2, step3)

# compose executes right-to-left
process = A.compose(step3, step2, step1)

Currying

All functions are automatically curried for partial application:

import aspis.common as A

# Built-in curried functions
add_five = A.add(5)
add_five(10)  # 15

# Curry your own functions
@A.curry
def greet(greeting, name):
    return f"{greeting}, {name}!"

say_hello = greet("Hello")
say_hello("Alice")  # "Hello, Alice!"

Predicates

Combine and compose logical operations:

import aspis.common as A

is_adult = lambda user: user['age'] >= 18
is_active = A.prop_eq('status', 'active')

# All predicates must pass
valid_user = A.all_pass([is_adult, is_active])

# Any predicate can pass
needs_review = A.any_pass([is_new_user, has_high_value])

Data Manipulation

Work with dictionaries and sequences functionally:

import aspis.common as A

# Get property
user = {'name': 'Alice', 'age': 30}
get_age = A.prop('age')
get_age(user)  # 30

# Set property (returns new dict)
updated = A.assoc('age', 31, user)

# Adjust value at index (returns new list)
numbers = [1, 2, 3, 4]
double = lambda x: x * 2
result = A.adjust(1, double, numbers)  # [1, 4, 3, 4]

List Operations

Transform and analyze sequences:

import aspis.common as A

# Create sliding windows
A.aperture(2, [1, 2, 3, 4])  # [[1, 2], [2, 3], [3, 4]]

# Add index to iterables
indexed_map = A.add_index(map)

Documentation

Full API documentation is available at: https://brihan.github.io/aspis/

Development

Setup

# Clone the repository
git clone https://github.com/brihan/aspis.git
cd aspis

# Install development dependencies
pip install -e '.[dev]'

Running Tests

pytest

Code Quality

# Format code
black .

# Lint code
flake8

Building Documentation

cd docs
make html

License

This project is licensed under the MIT License.

About

A functional programming library for Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages