aspis.common
Common functional programming utilities for Aspis.
This module provides the main public API for the Aspis library, including:
Function composition: pipe, compose
Currying: curry decorator for automatic partial application
Arithmetic operations: add, multiply, divide (all curried)
Predicates: all, any, all_pass, any_pass, equals, prop_eq
Data manipulation: prop, assoc, adjust
List operations: add_index, add_index_right, aperture
Function utilities: flip, identity, always, apply, apply_to, apply_spec
All exported functions support currying and are designed for composition.
Example
>>> import aspis.common as A
>>> users = [{'name': 'Alice', 'age': 30}, {'name': 'Bob', 'age': 25}]
>>> find_alice = A.prop_eq('name', 'Alice')
>>> alice = next(filter(find_alice, users))
>>> alice['name']
'Alice'
Modules
|
Curried addition function. |
|
Maps a function over a sequence, passing the index as a second argument, allowing the map function to have access to the index of the element being processed. |
|
Maps a function over the reversed sequence, passing both the index and the element to the function. |
|
Adjusts the element at the specified index in a sequence by applying a function to it. |
|
Returns True if all elements in the iterable satisfy the predicate. |
|
Checks if all predicates in the given sequence return True when applied to the input variable. |
|
Returns a function that always returns the same value. |
|
Returns True if any element in the array satisfies the predicate. |
|
Checks if any predicate in the given sequence returns True when applied to the input variable. |
|
Returns a new list containing lists of n consecutive elements from the original sequence. |
|
Alias for functools.partial - partial function application. |
|
Given a spec object recursively mapping properties to functions, creates a function producing an object of the same structure, by mapping each property to the result of calling its associated function with the supplied arguments. |
|
Takes a value and applies a function to it. |
|
Associates a value with a key in an object. |
|
Performs right-to-left function composition. |
|
Transforms a function into a curried version. |
|
Curried division function. |
|
Curried equality comparison function. |
|
Returns a new function much like the supplied one, except that the first two arguments' order is reversed. |
|
The identity function. |
|
Curried multiplication function. |
|
Performs left-to-right function composition. |
|
Returns the value of property p in object obj if it exists, otherwise return None |
|
Returns a check if the specified property of an object equals the given value. |