Skip to main content

Exact implementation of Java's Optional in Python with 100% test coverage.

Project description

pyoptional

Java-style Optionals for Python.

Installation

Simply install this package with your favourite package manager:

pip install pyoptional

or

poetry install pyoptional

Usage

The Optional class is a generic class that can be used to wrap a value that may or may not be None. Its functionality is roughly equivalent to Java's Optional class. For example:

Optional<String> opt = Optional.of("Hello, world!");
opt.ifPresent(System.out::println);

turns to the following Python code:

opt = Optional[str].of("Hello, world!")
opt.if_present(print)

Of course, type annotations in Python are optional (no pun intended), so you can simply write Optional.of("Hello, world!") if you prefer.

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

joptional-0.1.1.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

joptional-0.1.1-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file joptional-0.1.1.tar.gz.

File metadata

  • Download URL: joptional-0.1.1.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.2 Darwin/23.4.0

File hashes

Hashes for joptional-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c0de90542ab016451ee41a2bbc562a1c50869b61ef1b5706c75ebfa3670a82b0
MD5 a8cea7fb34e8c0c1963a7f12162e5924
BLAKE2b-256 ab0513769d90ed406183da93ab344befc3c8d0b31a8ddf52e8163ad6a5867081

See more details on using hashes here.

File details

Details for the file joptional-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: joptional-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.2 Darwin/23.4.0

File hashes

Hashes for joptional-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 486613262a099264ffff651f116915c489b05b8049555cb97153a0678daa32d7
MD5 7722a52c4c1af13b92be724bc30c89cb
BLAKE2b-256 4f75d515e0155819c25db77adcd4a759eca54678ba0fdbfb2585dcc9d9fffbac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page