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
Release history Release notifications | RSS feed
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 hashes)
Built Distribution
Close
Hashes for joptional-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 486613262a099264ffff651f116915c489b05b8049555cb97153a0678daa32d7 |
|
MD5 | 7722a52c4c1af13b92be724bc30c89cb |
|
BLAKE2b-256 | 4f75d515e0155819c25db77adcd4a759eca54678ba0fdbfb2585dcc9d9fffbac |