Skip to main content

Enable function chaining for any object.

Contained is a class that can wrap any type and make it possible to do function chaining on that object, much like functional piping.

Any method that is defined on the contained type is possible to call, whether it returns a copy or mutates in place. It is also possible to call operators and any builtin function, without breaking the chain. To get the original variable back out of the Contained, just call it with no args.

from contained import Contained
ex = ['hello', 'world']
Contained(ex)() == ex  # True

# methods
Contained(['hello']).extend(['world'])() == ex  # True

# operators
Contained(['hello']).add(['world']).contains('hello')()  # True

# builtins
Contained(ex).len().type()()  # <class 'int'>

Contained can also be given an additional namespace to allow for custom chained methods. This can be a module dict, class dict, globals, locals, or any other dict mapping names to objects.

def stringify_number_colleciton(c):
    return (s if not str(s).isdigit() else int(s) for s in c)

(Contained({1, "A", 3.02, ()}, additional_methods=locals())
    .stringify_number_colleciton()
    .sorted(key=lambda s: str(s))
    () == 
[(), 1, 3.02, 'A'])
import functools, itertools

# if you are on Python >= 3.9 use `additional_methods=(vars(functools) | vars(itertools))`
(Contained(42, reversed=True, additional_methods=Contained(vars(functools)).update(vars(itertools))())
    .range()
    .list()
    .takewhile(lambda x: x < 18)
    .dropwhile(lambda x: x <= 5)
    .map(hex)
    .reduce(lambda y, x: f"{y} {x}")
    () ==
"0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10 0x11")

Metadata

Release files for contained 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for contained 0.0.2
File Size Uploaded Provenance
contained-0.0.2.tar.gz 4.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for contained 0.0.2
File Interpreter ABI Platform
contained-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / contained-0.0.2.tar.gz

Download URL contained-0.0.2.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
62445ef57fe2b40ea636d62c972c53ca3750b80cd0759d1cd79598ea301e97f9
BLAKE2b-256 checksum
How to use checksums
07d2fe4a1b16710d09efdc80f0328889a36f7f25ea8c29b872f586b2aef8de08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.27.1

Release files / contained-0.0.2-py3-none-any.whl

Download URL contained-0.0.2-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba15152bf006f443ceb9e051583bc7b584a74a466c425c7c7e5aaa1544b139eb
BLAKE2b-256 checksum
How to use checksums
0bf37428191f018ba029bb33b78a0ae06958c0b3005a6567ae0c13b02882ae8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.27.1

Security for contained 0.0.2

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page