Java Optionals for Python
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.0.tar.gz
(2.3 kB
view hashes)
Built Distribution
Close
Hashes for joptional-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5268f60e12d826519fb2002b6459a3f40275d40fecdb57e4cd69631293bc587 |
|
MD5 | ea69475702f13d8946f67f630d9442dd |
|
BLAKE2b-256 | 97be2cf5c4feb1d3b27266e8a74690ffb8f32362d4c66e3cc1cd9723042cdf92 |