Socket
Socket
Sign inDemoInstall

joptional

Package Overview
Dependencies
0
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    joptional

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


Maintainers
1

Readme

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.

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc