Skip to main content

Utility functions for common tasks when composing functions.

Project description

composetools

Utility functions for Pythonic function composition. BYO compose() implementation.

Install

pip install composetools

Examples

from funcy import compose, rcompose

from composetools import unique, flat, sort


# Get unique items from nested iterables.
compose(sort, flat, unique)([[1, 2, 3], [4, 3, 2]])  # [1, 2, 3, 4]


# Get lines of a file.
from pathlib import Path
get_lines = rcompose(
    Path,
    Path.expanduser,
    Path.resolve,
    Path.read_text,
    str.splitlines,
)
get_lines("~/.gitconfig")

Functions

  • tap - Call a function but don't return the result, eg. tap(lambda x: print(x))(4) == 4
  • each - Curried version of map.
  • keep - Curried version of filter.
  • drop - Curried version of itertools.filterfalse.
  • sort - Curried version of sorted.
  • flat - Flatten an arbitrarily nested iterable.
  • unique - Yield unique items of an iterable.

Develop

$ git clone https://github.com/SeparateRecords/python-composetools
$ poetry install
$ poetry run tests

Licence

ISC

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

composetools-0.1.0.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

composetools-0.1.0-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

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