Skip to main content

A Python library for efficient array operations using a fluent API.

Project description

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 actionsLoop for 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.

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

arachnea-0.0.4.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

arachnea-0.0.4-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file arachnea-0.0.4.tar.gz.

File metadata

  • Download URL: arachnea-0.0.4.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for arachnea-0.0.4.tar.gz
Algorithm Hash digest
SHA256 a47bce1fceaeb2101b2951b1cc9b74d59c0c621945cedfeb6fd7ca9c62801ced
MD5 e9963273896c4c9296b6a363f3d3c3c0
BLAKE2b-256 37dbf99adcccb4cb07023801aebddd73ddb9bdf4ac64e8c56a290d09150a784f

See more details on using hashes here.

File details

Details for the file arachnea-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: arachnea-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for arachnea-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4d318c70bac65d0c135bf77d1e15a9c08527321f25fcad28eb4a3f8b1e2d48c9
MD5 580af524c77505fe873d8ca013fb4188
BLAKE2b-256 f4dd82f1b609ec302222f62c09827c8385f1bf00de7db49e1e0345d8db324087

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