Skip to main content

opytional

https://img.shields.io/pypi/v/opytional.svg https://img.shields.io/travis/mmore500/opytional.svg Documentation Status

opytional makes working with values that might be None safer and easier

Inspired by C++’s std::optional.

import opytional as opyt



# opyt.or_value
# provides a fallback value when value is None

opyt.or_value(None, 'fallback') # returns 'fallback'

opyt.or_value('value', 'fallback') # returns 'value'



# opyt.or_else
# provides a fallback callable when value is None

opyt.or_else(None, lambda: 'fallback') # returns 'fallback'

opyt.or_else('value', lambda: 'fallback') # returns 'value'



# opyt.apply_if
# applies an operator to value when value is not None

opyt.apply_if(None, lambda x: x + ' world') # returns None

opyt.apply_if('hello', lambda x: x + ' world') # returns 'hello world'



# opyt.apply_if_or_value
# applies an operator to value when value is not None
# with a fallback value for when value is None

opyt.apply_if_or_value(None, lambda x: x + ' world', 'fallback')
# returns 'fallback'

opyt.apply_if_or_value('hello', lambda x: x + ' world', 'fallback')
# returns 'hello world'

opyt.apply_if_or_value('hello', lambda x: None, 'fallback') # returns None



# opyt.apply_if_or_else
# applies an operator to value when value is not None
# with a fallback callable for when value is None

opyt.apply_if_or_else(None, lambda x: x + ' world', lambda: 'fallback')
# returns 'fallback'

opyt.apply_if_or_value('hello', lambda x: x + ' world', lambda: 'fallback')
# returns 'hello world'

opyt.apply_if_or_value('hello', lambda x: None, lambda: 'fallback')
# returns None

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2022-02-22)

  • First release on PyPI.

Metadata

Release files for opytional 0.1.0

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

Source distribution (sdist)

Source distribution for opytional 0.1.0
File Size Uploaded
opytional-0.1.0.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opytional 0.1.0
File Interpreter ABI Platform
opytional-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 16.8 kB

Release files / opytional-0.1.0.tar.gz

Download URL opytional-0.1.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
84eab1deca9fda36e8ed0c5743615f670264c479d73ae4cd5416b4701c927034
BLAKE2b-256 checksum
How to use checksums
8d870d2aa933b3689c57a9e431288d50fb618250c57ccb3aca03a62150733950
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release files / opytional-0.1.0-py2.py3-none-any.whl

Download URL opytional-0.1.0-py2.py3-none-any.whl
Size 5.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5504d36d3fa9b466d171336e92a11bde4dae52bf6878f26d539f8b688503f8e4
BLAKE2b-256 checksum
How to use checksums
28f1d282b5fdecd6b579b7fcc09ea2cb8a69837dd197acfe4a8d0806f5f3f931
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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