arachnea
arachnea is a Python library that allows you to perform efficient array operations using a fluent API approach inspired by the agility and efficiency of spiders.
Features
- Map: Transform each element of an array using a provided function.
- Filter: Filter elements of an array based on a provided condition.
- Reduce: Reduce an array to a single value based on a provided accumulator and transformation function.
- Find: Find the first element in the array that meets the given condition.
- Remove: Remove the first element in the array that meets the given condition.
- ForEach: Execute a provided function once for each array element.
Installation
You can install arachnea via pip:
pip install arachnea
Usage
Basic Usage
from arachnea import arachnea
numbers = [1, 2, 3, 4, 5]
arachnea(numbers).for_each(lambda num: print(num * 2)) # Example of using forEach
API Examples
Mapping and Reducing
numbers = [1, 2, 3, 4, 5]
sum_of_squares = (
arachnea(numbers)
.map(lambda num: num * num)
.reduce(lambda acc, num: acc + num, 0)
)
print(sum_of_squares) # Output: 55
Filtering and Collecting
numbers = [1, 2, 3, 4, 5]
odd_numbers = (
arachnea(numbers)
.filter(lambda num: num % 2 != 0)
.collect()
)
print(odd_numbers) # Output: [1, 3, 5]
Removing Elements
numbers = [1, 2, 3, 4, 5]
remove_4 = (
arachnea(numbers)
.map(lambda num: num * num)
.remove(4)
.collect()
)
print(remove_4) # Output: [1, 9, 16, 25]
Finding Elements
numbers = [1, 2, 3, 4, 5]
greater_than_twenty_four = (
arachnea(numbers)
.map(lambda num: num * num)
.find(lambda num: num > 24)
)
print(greater_than_twenty_four) # Output: 25
Chaining Operations
numbers = [1, 2, 3, 4, 5]
result = (
arachnea(numbers)
.filter(lambda num: num > 2)
.map(lambda num: num * 3)
.reduce(lambda acc, num: acc + num, 0)
)
print(result) # Output: 39
API
map(transformer: (element: T) => K) -> Stream[K]
Transforms each element of the array using the provided transformer function.
filter(condition: (element: T) => bool) -> Stream[T]
Filters elements of the array based on the provided boolean condition function.
reduce(reducer: (accumulator: K, element: T) => K, initial_value: K) -> K
Reduces the array to a single value using the provided reducer function and initial value.
remove(condition: (element: T) => bool | T) -> Stream[T]
Removes the first element in the array that meets the given condition or is equal to the given parameter.
find(condition: (element: T) => bool | T) -> T
Finds the first element in the array that meets the given condition or is equal to the given parameter.
for_each(action: (element: T) => None) -> None
Executes a provided function once for each array element.
collect() -> List[T]
Collects the elements after applying all transformations and filters, returning them as a list.
Todo
- Combine successive filter operations into a single operation.
- Document
actionsLoopfor custom terminating operation injection. - Improve the performance of atomic operations.
- Add sorting, flattening functionality.
- Enhance performance optimizations.
- Implement error handling for edge cases.
Contributing
Contributions are welcome! Please fork the repository and submit a pull request.
Metadata
Release files for arachnea 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| arachnea-0.0.5.tar.gz | 5.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| arachnea-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / arachnea-0.0.5.tar.gz
| Download URL | arachnea-0.0.5.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d27f23c713c810e458eaa919a4066bab475176b6ecf2b035fac3c59a74c8a655
|
|
BLAKE2b-256 checksum How to use checksums |
96ca63ebf04386a653d1a9e76bf092d0d01255613f8b24e1d921c0e6303873be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.18
|
Release files / arachnea-0.0.5-py3-none-any.whl
| Download URL | arachnea-0.0.5-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7191613bbd108f74d0658f870bebdd8ff737289cd1af9fcbfac5756598893fe
|
|
BLAKE2b-256 checksum How to use checksums |
0fddf4bf8c3df5d7ff267fb6e58585d2cc58fc3cdde8b441f6bb9ce9c04f953b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.18
|
Security for arachnea 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.